advertisement
javaboutique
Search Tips
Articles  |   Tutorials  |   Reviews  |   Tools  |   by Category  |   by Date  |   by Name  |   Submit  |   Source  |   Forums  |  
javaboutique
Browse DevX


Partners & Affiliates











advertisement

Tutorials : Using FOP with Java :

Using FOP with Java - Part 1

by: Samudra Gupta

Introduction

In data-centric applications, you are often required to produce reports and documents in various formats. One of the challenges facing the developer world is to find a generic and consistent way of manipulating a structurally diverse data set to produce formatted reports. For example, if you write a program to accept a certain data set and produce a PDF formatted report, than in order to produce an HTML report on the same data set you might have to write a different program. In this article, we will see a relatively new technology involving W3C standard named XSL-FO. FOP gives us the flexibility to operate on XML structured data, apply an XSL Stylesheet, do the XSLT transformation and publish the data in various formats such as PDF, PCL, SVG, TXT and many other.

What is FOP

Formatting Object Processor (FOP) is a Java based print formatter based on the XSL-FO (XSL-Formatting Object) standard. FOP is capable of reading a FO object tree and renders the resulting page into a specified output format. FOP currently supports the following output formats:

  • PDF (The default output format).
  • TXT
  • PCL (For HP PCL Printers)
  • PS (Postscript)
  • SVG (Scalar Vector Graphics)
  • XML (Area Tree representation)
  • Print
  • AWT
  • MIF (Maker Interchange Format, used by Adobe)

With the help of FOP, the generated output can be stored in a file format in the hard drive or can be directly sent to a different output device such as browser, printer etc.

Getting FOP

You can download the current FOP implementation from http://xml.apache.org/fop. FOP depends on other .jar files being in the classpath. These .jar files come bundled with the FOP distribution. You can refer to the documents in the FOP distribution for the .jar files that need to be in the classpath.

Basics of FOP

One of the major benefits of FOP is it is so simple to use. Again, it is simple because it works on a very simple foundation. In this section, we will examine the basic working model of FOP.

Black-box view

The black-box view of FOP is like this: black box view

In the black-box view, the user provides a XML input and a XSL to the FOP engine. The FOP engine outputs either a XSL-FO file (.fo extension) or renders the documents in PDF, SVG, PS etc. For example, let us consider that you have a simple XML file data.xml (Listing-1). You want to produce a PDF file out of that using the XML pdfGen.xml (Listing-2). You can use FOP command line in the following manner:

fop -xsl pdfGen.xsl -xml data.xml -pdf data.pdf

This will generate a data.pdf file containing the data specified in the data.xml file and formatted according the formatting routines specified in the pdfGen.xsl file.

Figure -1 shows the PDF output.

Data

Figure-1: The sample PDF output

White-box view

The white-box view of FOP presents different internal components of FOP. In general, the FOP consists of the following different component sections.

  • Parsing: Parsing of the XML input and the XSL-FO input. FOP uses SAX to parse the input XML and XSL-FO file and prepares the information for the core FOP engine. At this stage, files are checked for well formed. If the files are well-formed, then XSLT is used to produce an intermediate FO object tree.
  • Layout: The Layout managers understand a FO-tree and convert them to the target output layout system. The Layout managers sit between the raw FO documents and the final output.
  • Rendering: Renderer objects are responsible for producing the final output in a predefined output format.

With this we finish the introduction to FOP and next we will see some practical example of using FOP.

Using FOP with Java - Part 2
Graphics with FOP - Part 3

How to Add Java Applets to Your Site

New on the Java Boutique:

New Review:

Time Management Made Easy with the Quartz Enterprise Job Scheduler
Why not just use the Java timer API? This open source scheduling API boasts simplicity, ease-of-integration, a well-rounded feature set, and it's free!

New Applet:

Reverse Complement
Reverse Complement is a simple applet that converts DNA or RNA sequences into three useful formats.

Elsewhere on internet.com:

WebDeveloper Java
Lots of Java information on webdeveloper.com

WDVL Java
Thorough Java resource at the Web Developer's Virtual Library.

ScriptSearch Java
Hundreds of free Java code files to download.

jGuru: Your View of the Java Universe
Customizable portal with online training, FAQs, regular news updates, and tutorials.

 Internet.com eBook Library
 IBM Software Construction Toolbox
 Microsoft RIA Development Center
 Destination .NET
XML error: not well-formed (invalid token) at line 38
advertisement
Receive Articles via our XML/RSS feed
Receive Articles via our XML/RSS feed

JavaBytes
Internet Cyclone
This powerful, easy-to-use, internet optimizer is for Windows 95, 98, ME, NT, 2000 and XP. It's designed to automatically optimize your Windows settings, boosting your Internet connection up to 200%.

Mozilla's Ubquity Mashup: For The Masses?
iPhone Users Just Want to Have Fun
Oops! I Fixed the Linux Kernel
Jim Zemlin: The New Center of Linux Gravity
Microsoft's Novell Investment Tops $340M
Fedora 10 Takes Shape
IBM Gives a Mobile Voice to Developers
Inadequate Tools Send Software Down the Drain
USB 3.0 One Step Closer to Reality
Would-Be Linux Contributors May Get a Leg Up

State of the Semantic Web: Know Where to Look
A 3D Exploration of the HTML Canvas Element
Setting Up and Running Subversion and Tortoise SVN with Visual Studio and .NET
Java/JRuby Developers, Say Open 'Sesame' to the Semantic Web
Interpreting Images with MRDS Services
DevXtra Editors' Blog: Executives Avoiding Cloud Computing in Droves
Q&A with James Reinders on the Intel Parallel Studio Beta Program
The Pros and Cons of Outsourcing Enterprise Emails
Hosting Options: Shared or Dedicated Server
Movin' On Up: How to Hop to a New Host

Advertising Info  |   Member Services  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About



JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers