From 46f47c3095c086d88ff7d652aee40303a9ed9601 Mon Sep 17 00:00:00 2001
From: Simon Pepping
- To embed Apache FOP in your application, instantiate a new org.apache.fop.apps.FopFactory - instance and create a new org.apache.fop.apps.Fop instance through one of the factory - methods of FopFactory. There, you can specify which output format (i.e. Renderer) to use - and you can optionally set the OutputStream to use to output the results of the - rendering. You can customize FOP's behaviour by supplying - your own FOUserAgent instance. The FOUserAgent can, for example, be used to - set your own Renderer instance (details below). Finally, you retrieve a SAX - DefaultHandler instance from the Fop instance to which you can send your - FO file. + To embed Apache FOP in your application, first create a new + org.apache.fop.apps.FopFactory instance. This object can be used to launch multiple + rendering runs. For each run, create a new org.apache.fop.apps.Fop instance through + one of the factory methods of FopFactory. In the method call you specify which output + format (i.e. Renderer) to use and, if the selected renderer requires an OutputStream, + which OutputStream to use for the results of the rendering. You can customize FOP's + behaviour in a rendering run by supplying your own FOUserAgent instance. The + FOUserAgent can, for example, be used to set your own Renderer instance (details + below). Finally, you retrieve a SAX DefaultHandler instance from the Fop object and + use that as the SAXResult of your transformation.
getDefaultHandler()
to obtain a SAX
DefaultHandler instance to which you can send the SAX events making up the XSL-FO
document you'd like to render. FOP processing starts as soon as the DefaultHandler's
- startDocument()
methods is called. Processing stops again when the
+ startDocument()
method is called. Processing stops again when the
DefaultHandler's endDocument()
method is called. Please refer to the basic
usage pattern shown above to render a simple XSL-FO document.
@@ -214,10 +215,10 @@ try {
on the basic usage pattern above is to set up the Transformer differently:
@@ -225,7 +226,7 @@ try {
- The input XSL-FO document is always handled internally as SAX (see the + The input XSL-FO document is always received by FOP as a SAX stream (see the Parsing Design Document for the rationale).
@@ -243,19 +244,19 @@ try {
File: Source src = new StreamSource(new File("C:/Temp/myinputfile.xml"));
Source src = new StreamSource(new StringReader(myString)); //myString is a String
+ String: Source src = new StreamSource(new StringReader(myString)); // myString is a String
Source src = new StreamSource(new MyInputStream(something));
Source src = new StreamSource(new ByteArrayInputStream(myBuffer)); //myBuffer is a byte[] here
+ Byte Array: Source src = new StreamSource(new ByteArrayInputStream(myBuffer)); // myBuffer is a byte[] here
Source src = new DOMSource(myDocument); //myDocument is a Document or a Node
+ DOM: Source src = new DOMSource(myDocument); // myDocument is a Document or a Node
@@ -299,8 +300,8 @@ try {
Enable an alternative set of rules for text indents that tries to mimic the behaviour of many commercial - FO implementations that chose to break the specification in this aspect. The default of this option is - 'false' which causes Apache FOP to behave exactly as describes in the specification. To enable the + FO implementations, that chose to break the specification in this respect. The default of this option is + 'false', which causes Apache FOP to behave exactly as described in the specification. To enable the alternative behaviour, call:
@@ -310,23 +311,23 @@ try { Set the source resolution for the document. This is used internally to determine the pixel size for SVG images and bitmap images without resolution information. Default: 72 dpi. Example: - +- Manually add a ElementMapping instance. If you want to supply a special FOP extension + Manually add an ElementMapping instance. If you want to supply a special FOP extension you can give the instance to the FOUserAgent. Normally, the FOP extensions can be automatically detected - (see the documentation on extension for more info). + (see the documentation on extension for more info). Example:
- +Set a URIResolver for custom URI resolution. By supplying a JAXP URIResolver you can add custom URI resolution functionality to FOP. For example, you can use - Apache XML Commons Resolver to make use of XCatalogs. + Apache XML Commons Resolver to make use of XCatalogs. Example:
- +The user agent is the entity that allows you to interact with a single rendering run, i.e. the processing of a single document. If you wish to customize the user agent's behaviour, the first step is to create your own instance - of FOUserAgent using the respective factory method on FopFactory and pass that + of FOUserAgent using the appropriate factory method on FopFactory and pass that to the factory method that will create a new Fop instance:
You can do all sorts of things on the user agent: @@ -400,7 +403,7 @@ try { (such as the TIFF renderer) and by bitmaps generated by Apache Batik for filter effects and such. Default: 72 dpi. Example:
- +@@ -408,7 +411,7 @@ try { configure a Renderer in a special way you can give the instance to the FOUserAgent. Normally, the Renderer instance is created by FOP. Example:
- +@@ -416,15 +419,15 @@ try { configure an FOEventHandler subclass in a special way you can give the instance to the FOUserAgent. Normally, the FOEventHandler instance is created by FOP. Example:
- +Set a URIResolver for custom URI resolution. By supplying a JAXP URIResolver you can add custom URI resolution functionality to FOP. For example, you can use - Apache XML Commons Resolver to make use of XCatalogs. + Apache XML Commons Resolver to make use of XCatalogs. Example:
- +
To get the number of pages that were rendered by FOP you can call
Fop.getResults()
. This returns a FormattingResults
object
- where you can lookup the number of pages produced. It also gives you the
+ where you can look up the number of pages produced. It also gives you the
page-sequences that were produced along with their id attribute and their
- number of pages. This is particularly useful if you render multiple
+ numbers of pages. This is particularly useful if you render multiple
documents (each enclosed by a page-sequence) and have to know the number of
pages of each document.
fop.setOutputStream(new java.io.BufferedOutputStream(out));
+ out = new java.io.BufferedOutputStream(out);
Templates
object and reuse it each time you do
+ you can set up a JAXP Templates
object and reuse it each time you do
the XSL transformation. (More information can be found
here.)
The directory "{fop-dir}/examples/embedding" contains several working examples. - In contrast to the examples above the examples here primarily use JAXP for - XML access. This may be easier to understand for people familiar with JAXP.
-The XMLReader implementation (regard it as a special kind of XML parser)is +The XMLReader implementation (regard it as a special kind of XML parser) is responsible for creating SAX events from the Java object. The InputSource class is only used to hold the ProjectTeam object to be used.
@@ -660,7 +661,7 @@ use a DOM tree as input for an XSL transformation.This example -shows use of the PDF Transcoder, a sub-application within FOP. +shows the usage of the PDF Transcoder, a sub-application within FOP. It is used to generate a PDF document from an SVG file.
- PDF has a set of fonts that are always available to all PDF viewers,
+ PDF has a set of fonts that are always available to all PDF viewers;
to quote from the PDF Specification:
"PDF prescribes a set of 14 standard fonts that can be used without prior
@@ -201,7 +201,7 @@ out = proc.getOutputStream();]]>
-