September 23, 2004
iText in Anger

Well, I've knocked up some stuff for real using iText now. The rose-tinted glasses are off for sure, but I have to say, it's a good solution.

Writing a long complex report with a lot of formatting is pretty dull, it must be said. But that's the nature of the beast, really - northing's going to make report generation exciting. iText does at least make it relatively easy to get exactly the result you need.

The mailing list, as I usually find in the open source world, pisses all over the "support" that you'll get from the proprietary world. So, a big thank you to Bruno Lowagie and Paulo Soares, not only for writing iText in the first place, but for their time over on itext-questions.

The code that you have to write is pretty ugly, I must say. It's really procedural, and it's long. There are a lot of repetitious sections that look like they could be refactored into methods to avoid code duplication, but that you find are different enough that you can't - at least, not without making the code really complex. And while the report generation code is long, it's also very simple; add a paragraph, add a table cell, add another table cell, and so on, and so on.

One thing I would like to be able to work out how to do is unit test. I already know that my domain objects work - they have their own unit test. So I really just need to make sure that the PDFs are generated correctly, and I can only do that by eye. Anyone have any good suggestions here?

Anyway, in short, I wouldn't hesitate to recommend iText over StyleReport or the like to anyone who can code.

Posted to Java by Simon Brunning at September 23, 2004 01:23 PM
Comments

Perhaps an intermediate unit test would be to verify that the composite objects - paragraph, tables, sections, etc, are correctly linked together/set up.
That is, run the report file out in test mode, and verify that
(a) the right file name was produced and it contains a non-zero number of bytes, maybe even shell it into acrobat and check if no errors occur, and
(b) then inspect the objects created inside your class to see thet they have the right structure.

Might not be the best, but it will certainly be a start.

Posted by: Mark Matthews on September 23, 2004 01:37 PM

Do you try the Form filling with itext
it rocks
;)

Posted by: Marc on September 23, 2004 02:41 PM

You should avoid testing iText itself I think, unless you have a seperate acceptance test. Therefore, you should test what you are passing to iText in the first place - does iText take XML as an input? If so, you could use XPath queries (XPath is built in to Java 1.4) to check the content of the code, or even simple string comparisons. The XPath queries will be less brittle than a simple text comparison, but might be more work (but also I suspect more maintainable).

Posted by: Sam Newman on September 23, 2004 03:40 PM

You don't really pass it anything except for chunks of string - you just call a bunch of iText classes. So, for example, I create a paragraph of mixed format text like so:

currentCell.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell(new Paragraph("(8)", FONT_BODY));
paragraph = new Paragraph();
paragraph.add(new Chunk("A separate Section B should be completed for each different ",
FONT_BODY));
paragraph.add(new Chunk("Currency", FONT_BODY_BOLD));
paragraph.add(new Chunk(
". Where the names of currencies are similar – for example US Dollars and Australian Dollars – these should be clearly stated. If it is unclear what currency your claim is in, your claim for voting purposes may be rejected in whole or in part.",
FONT_BODY));
currentCell.setHorizontalAlignment(Element.ALIGN_JUSTIFIED);
table.addCell(paragraph);

Posted by: Simon Brunning on September 23, 2004 03:47 PM

Well, there are two things you can test in that case

1.) That you are making the right iText calls based on program execution - so make sure your code calls addCell in the right places. For that you just have to Mock out the paragraph and replace some of your constructors with a factory.

2.) Just do manual acceptance tests on the reports.

I guess it depends on how many reports you have - if you have one or two then manual acceptance tests should be so bad. If you have loads though (or an overworked QA) the work to allow automated testing might be worth it.

Posted by: Sam Newman on September 23, 2004 04:27 PM

Even simpler, just abstract out your use of iText altogether, then mock your abstraction when testing. Then you're not testing iText, but your use of iText, which is as it should be. I kind of meant that before, but wasn't very clear :-)

Posted by: Sam Newman on September 23, 2004 04:28 PM

"And while the report generation code is long, it's also very simple"... there's always the Ghetto mini-pattern for dealing with that. And if it's a pattern, it has to be good...
http://fishbowl.pastiche.org/2003/05/28/the_ghetto_minipattern

Posted by: Alan Green on September 23, 2004 09:58 PM

Half my bloody project is a Ghetto...

Posted by: Simon Brunning on September 24, 2004 08:44 AM

Have you thought about using Apache FOP and XSL-FO for reporting?

Posted by: Ben Galbraith on September 24, 2004 04:11 PM

pdytixal kmqnygow zqhk zfaeurpd gxvwaouc cjnd xvlbfwns http://www.nexbdtsq.zvdn.com

Posted by: ptnjas wmsre on March 30, 2009 06:59 AM

yvsxzr nbqucvt
http://carnival-cruise.greatnow.com/index.html carnival cruise

Posted by: carnival cruise on March 30, 2009 11:30 AM

tavbnid
http://postcard-printing.greatnow.com/index.html postcard printing

Posted by: postcard printing on March 31, 2009 01:50 AM

sfnbyac
http://postcard-printing.greatnow.com/postcard-printing-software.html postcard printing software

Posted by: postcard printing software on March 31, 2009 10:06 AM

sfnbyac
http://postcard-printing.greatnow.com/postcard-printing-software.html postcard printing software

Posted by: postcard printing software on March 31, 2009 10:06 AM

uoclar
http://drug-detox.greatnow.com/index.html drug detox

Posted by: drug detox on April 1, 2009 06:58 PM

$1,15Buy Generic Viagra
Buy Online Viagra
Buy Cheap Viagra
Viagra Buy
Buy Viagra
Buy Viagra On Line
Buy Viagra Now Online
Where Buy Generic Viagra
Buy Generic Viagra
http://www.english.heacademy.ac.uk/virtue/user/view.php?id=2246&course=1&key=Buy+Viagra+Now+Online Buy Cheap Viagra
http://www.english.heacademy.ac.uk/virtue/user/view.php?id=2246&course=1&key=Buy+Online+Viagra Where To Buy Viagra
http://www.english.heacademy.ac.uk/virtue/user/view.php?id=2246&course=1&key=Buy+Viagra Viagra Buy
http://www.itce.alquds.edu/etraining/user/view.php?id=6108&course=1&key=Buy+Viagra Viagra Buy
http://www.irel-open.ie/user/view.php?id=15289&course=1&key=Buy+Viagra+Alternative Where Buy Generic Viagra
http://www.irel-open.ie/user/view.php?id=15289&course=1&key=Buy+Viagra+Now+Online Viagra Buy
http://motivate.maths.org/moodle/user/view.php?id=1807&course=1&key=Buy+Viagra+Alternative Buy Viagra Now
http://www.english.heacademy.ac.uk/virtue/user/view.php?id=2246&course=1&key=Buy+Viagra+On+Line Buy Generic Viagra
http://www.medvetnet.org/moodle/user/view.php?id=118&course=1&key=Buy+Viagra+On+Line Buy Viagra Alternative

viagra plant buy viagra canada herbal viagra australia viagra softtabs florida viagra online viagra reviewa buy viagra search find free viagra blue big love bush buy porn viagra edinburgh pages free find viagra search viagra before and after viagra discount sales generic name viagra buy viagra in malaysia enzyte vs viagra methadone and viagra by mail sale viagra good screw with viagra href bigger erection with viagra what is viagra affiliate directory viagra generic viagra sold on line the city that viagra built generic viagra no prescriptio in use viagra woman success of viagra pharmaceutical canadian approved female viagra order viagra now discount viagra furthermore cheap adipex reviews canadian drug viagra actress viagra sports show tape commercial viagra drugs online health south cover viagra buy viagra phentermine meridia adipex xenical low cost generic viagra barefoot man viagra mail viagra viagra 100mg tablets no prescription cheap viagra description viagra contents of viagra cheap levitra tramadol ultram viagra viagra british store boot 3 cialis generic levitra viagra generac viagra viagra ejaculation 3 generic sildenafil viagra uprima cialis viagra viagra sell viagra seller viagra sample overnight delivery viagra the pill vrx v herbal viagra will viagra work on young males snoring and viagra viagra student loan consolidation buy viagra for women can i buy viagra with paypal viagra retail discount

Posted by: NeadlyjatHata on April 3, 2009 11:08 AM

qmtv
http://tanning-bedss.greatnow.com/index.html tanning beds

Posted by: tanning beds on April 6, 2009 05:11 PM
Post a comment
Name:


Email Address:


URL:



Comments:


Remember info?