Adobe's Portable Document Format (PDF) is a popular choice for exchanging documents over the Internet, but how do you access and present PDF files in your Java applications? Jeff Friesen introduces this month's Open Source Java Project: a PDF rendering tool that you can easily integrate with your Java applications.
Java-based products such as Bruno Lowagie's iText make it easy for Java programs to create PDF documents. For example, a servlet could extract product data from a database, and then use iText to dynamically create a PDF-based product catalog based on this data. iText and products like it aren't designed to render a PDF document's content, however.
A few years back, Sun Labs researchers developed the all-Java PDF Renderer project because they needed a PDF viewer for content created by OpenOffice. When this project was no longer needed, Sun Labs offered PDF Renderer to Josh Marinacci and Richard Bair (of SwingLabs) who set out to get the project open sourced. Tom Oke signed on to head up future work on the project, and Josh announced the release of the open source PDF Renderer project in December 2007.
In this installment in the Open Source Java Projects series, I'll introduce you to the SwingLabs PDF Renderer. After you've downloaded the project source and run a short demo, we'll explore the PDF Renderer API. Following application exercises in rendering PDF content to your application screen and sending it to a printer, I'll wrap up with a more complex example that demonstrates PDF Render's usefulness.
| This project's license |
|---|
| PDF Renderer adheres to the GNU Lesser General Public License (LGPL). See the Resources section to learn more about this open source license. |
The pdf-renderer project, hosted on Java.net, introduces PDF Renderer and provides access to its executable and source code. Point your browser
to the site's "Documents & files" section and download the most recent version of PDF Renderer's distribution archive. For
example, I downloaded PDFRenderer-2008_05_18-bin.zip.
The distribution archive contains a JAR file that stores the API's class files. The archive also stores the class files to
a PDF viewer demo that demonstrates the API's usefulness for viewing arbitrary PDF documents. You can run this demo at the
command line by specifying the following command (assuming that the current directory contains PDFRenderer-2008_05_18.jar):
java -jar PDFRenderer-2008_05_18.jar
Figure 1 shows the demo presenting the first page of a sample PDF document. The left pane of the demo's split-pane GUI reveals this document's thumbnail images, which you can click to select the page that appears in the right pane. The right pane presents the current page; you can zoom into this page by selecting the toolbar's magnifying tool and selecting a rectangular area.
The distribution archive also contains Javadoc-based documentation, which describes PDF Renderer's API. This documentation
is separately available in its own archive -- PDFRenderer-2008_05_18-javadoc.zip, for example. Also in its own archive is the source code to the API and demo. For the previously mentioned distribution archive,
PDFRenderer-2008_05_18-src.zip is the equivalent source archive.
| Subject |
|
|
chinese supportBy Anonymous on October 13, 2009, 5:49 amis it support chinese? i.e: http://www.esigntrust.com/cn/repository/Forms/DSC-AAC-PersonalCert-CE-2006-01.01p.pdf
Reply | Read entire comment
java sample projectsBy Anonymous on August 19, 2009, 2:39 ami want to practice a project
Reply | Read entire comment
PDF to pngBy Anonymous on May 8, 2009, 2:35 amHi, i am trying to convert a pdf byte array into a png byte array. Using pdf renderer, i am able to convert fioles located on a disk. The conversion does not work...
Reply | Read entire comment
Sending PDF document to printerBy venkatsalem on November 22, 2008, 10:09 pmNice article. I just want to add one additional points here. Using PDF renderer it is possible to send the PDF document to printer. You can find sample code in my...
Reply | Read entire comment
View all comments