The Artima Developer Community
Sponsored Link

Java Community News
Joshua Marinacci on Generating PDF from XHTML

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Frank Sommers

Posts: 2642
Nickname: fsommers
Registered: Jan, 2002

Joshua Marinacci on Generating PDF from XHTML Posted: Jun 28, 2007 3:36 PM
Reply to this message Reply
Summary
In a recent tutorial, Sun's Joshua Marinacci describes how XHTML and the iPDF library can be combined to generate high-quality, print-ready PDF documents from dynamic Web page content.
Advertisement

Generating PDFs in Java was made a lot easier by Bruno Lowagie's iText library. In a recent java.net article, Generating PDFs for Fun and Profit with Flying Saucer and iText, Josh Marinacci explains how to generate PDFs from dynamic Web content using iText in conjunction with the open-source XHTML renderer library, Flying Saucer:

Flying Saucer.. is an LGPLed Java library on java.net originally created by me and continually developed by the java.net community. Flying Saucer's primary purpose is to render spec-compliant XHTML and CSS 2.1 to the screen as a Swing component. Though it was originally intended for embedding markup into desktop applications.. Flying Saucer has been extended work with iText as well. This makes it very easy to render XHTML to PDFs, as well as to images and to the screen...

iText is a PDF generation library created by Bruno Lowagie and Paulo Soares, licensed under the LGPL and the Mozilla Public License... Using the iText API, you can produce paragraphs, headers, or any other PDF feature. Since the PDF imaging model is fairly similar to Java2D's model, Flying Saucer and iText can easily work together to produce PDFs...

In the article, Marinacci points out that while HTML content is almost always intended to be displayed inside a browser, PDF documents, by contrast, are aimed primarily for pretty printing. Thus visual appearance on the printed page is an important consideration for PDF generation. The Flying Saucer and iText solution Marinacci outlines takes this difference into account:

Paged media like printed documents or slideshows have certain features specific to pages. In particular, pages have specific sizes and margins. Text laid out for an 8 1/2 by 11 inch piece of paper will look very different than text for a paperback book, or a CD cover. In short, pages matter, and Flying Saucer gives you some control over pages using page-specific features in CSS.

Another feature Marinacci shows in the article is the ability to add images to a PDF document in a way that's friendly to the printed page. The examples in the article use CSS for styling the printed output.

What are your favorite methods of generating PDF from dynamic content?

Topic: Neal Gafter on Constructor Type Inference in Java Previous Topic   Next Topic Topic: JavaOne, Day 3: Java Puzzlers

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use