News on Monday
more>>
SharePoint Tech Report
more>>


   

 
 
Download Current Issue
ISSUE 7/1/2009 PDF

Need Back Issues?
DOWNLOAD HERE

Receive the print Edition?


 
Is the mystery Borland suitor Serena?
Borland software is considering an offer from another company after a preliminary deal with MicroFocus. Is Serena the new company?
06/30/2009 01:55 PM EST

Windows 7 - An eBayer's dream product?
Windows 7 pre-orders can make people money on eBay.
06/29/2009 03:48 PM EST

Know thine cloud provider
Cloud computing require companies to understand compliance and regulation. Third parties will play a big role in regulated industries.
06/29/2009 02:58 PM EST

 

Microsoft Worldwide Partner Conf.
7/13/2009 to 7/16/2009
New Orleans
Microsoft

OSCON (Open Source Convention)
7/20/2009 to 7/24/2009
San Jose
O'Reilly Media

XBRL Technology Workshop & Summit
7/28/2009 to 7/30/2009
Santa Clara
XBRL US

ACM SIGGRAPH
8/3/2009 to 8/7/2009
New Orleans
ACM SIGGRAPH

OpenSource World (formerly LinuxWorld)
8/12/2009 to 8/13/2009
San Francisco
IDG World Expo


 
Most Read Latest News Blog Resources

I Text, You Text, We All Text for iText




January 15, 2006 — 
I have a soft place in my heart for typesetting systems. I’ve built several over the ages, and have typeset many of my own books. My monthly C Chest column in Dr. Dobb’s Journal was canned in 1987 largely because of my “wasting” three months presenting the source code for my version of a markup-language interpreter that did layout: troff. (The editor insisted that both Unix and markup languages were irrelevant, obsolete technologies. For what it’s worth, Bill Gates was saying exactly the same thing about HTML at the time.)

I’m going to try my luck again: In my Dec. 15 column, I promised that I’d report back on a typesetting system: iText, Bruno Lowagie and Paulo Soares’ PDF-creation library. Let’s pick up that thread.

To refresh your memory, a project required me to create a few simple printed reports—the complete contents of which weren’t known until runtime—in CSV, HTML and PDF formats. I rejected JasperReports, which I found to be an overly complicated, poorly documented nonsolution to this problem. You know something’s wrong when it’s harder to use the tool than it is not to use the tool.

The iText library—the PDF-generation library that JasperReports uses—is, on the other hand, very good. iText is a full-blown typesetting system that lets you do in Java pretty much everything you can do with PostScript. You can use iText to lay out complex documents containing both text and images to produce a PDF representation. (Note that iText also can produce HTML and RTF files, but it doesn’t do as good a job in these formats as it does with PDF. The table-layout classes, essential for reporting applications, work only with PDF output, for example.)

Though it does have all the low-level APIs that you need to build a real typesetting system, the real strength of iText is the high-level objects that let you manipulate the document at the level of paragraph and chunk. (A chunk is part of a paragraph.) You assemble a paragraph simply by adding chunks of text to it, and can easily modify paragraph attributes like font size and margins. There’s also a very nice set of table-creation objects. The vast majority of applications can get by with nothing but these simple-to-use APIs.

On the output side, iText uses the Builder design pattern. You attach a “writer” as defined by that pattern to the document you’re creating, and that writer takes care of the mechanics of building a particular output format. That is, you can create a document without needing to know whether the ultimate output format will be pdf, rtf, html and so on.iText documentation is a mixture of the usual JavaDoc and an online tutorial called “iText by Example.” The fact that this tutorial is not printable is a definite negative, but it’s well organized and easier to use than many online tutorials. The tutorial presents the material in a linear way that guides you through the entire library, as compared with a blob of links that force you to bounce around in the material more or less randomly. There are a few minor linguistic anomalies (the author likes to say “Remark that” instead of “Note that,” for example), but they don’t get in the way of readability.

The main problem with the tutorial is that it’s not complete. The PDF-Form-generation mechanisms are not covered, for example.

Very much on the plus side, the tutorial is laid out using a use-case approach that I’ve advocated in the past. It focuses on tasks that you are likely to perform, then tells you how to accomplish those tasks. It’s also organized in such a way that you can get to work immediately if you’re doing simple stuff, relegating the gory details that you’re not likely to need to later sections. There are plenty of coding examples.

Consequently, I’ve decided to code directly to the iText APIs rather than using a report-generation package like Jasper. The resulting report will be both better looking and easier to code than the Jasper equivalent. Moreover, though iText can create HTML output, it is easily integrated into a Servlet to deliver PDF directly to the browser. Since this way of working gives me a better-looking page than the HTML, I plan to skip the HTML entirely and just present PDF to the user. And the icing on the cake is that I can do iText without any XML whatever. I’m happy. And I still have my column! z

Allen Holub is an architect, consultant and instructor in C/C++, Java and OO Design. Reach him at www.holub.com.


Share this link: http://www.sdtimes.com/link/29077
 

Add comment


Name*
Email*  
Country     


  • Comment
  • Preview
Loading