You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlgraphics.apache.org by ps...@apache.org on 2010/06/18 13:52:38 UTC

svn commit: r955955 [6/8] - in /xmlgraphics/site/deploy/fop: ./ dev/ trunk/

Modified: xmlgraphics/site/deploy/fop/trunk/embedding.html
URL: http://svn.apache.org/viewvc/xmlgraphics/site/deploy/fop/trunk/embedding.html?rev=955955&r1=955954&r2=955955&view=diff
==============================================================================
--- xmlgraphics/site/deploy/fop/trunk/embedding.html (original)
+++ xmlgraphics/site/deploy/fop/trunk/embedding.html Fri Jun 18 11:52:37 2010
@@ -1,1135 +1,1135 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
-<html>
-<head>
-<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
-<meta content="Apache Forrest" name="Generator">
-<meta name="Forrest-version" content="0.9-dev">
-<meta name="Forrest-skin-name" content="pelt">
-<title>Apache FOP: Embedding</title>
-<link type="text/css" href="../skin/basic.css" rel="stylesheet">
-<link media="screen" type="text/css" href="../skin/screen.css" rel="stylesheet">
-<link media="print" type="text/css" href="../skin/print.css" rel="stylesheet">
-<link type="text/css" href="../skin/profile.css" rel="stylesheet">
-<script src="../skin/getBlank.js" language="javascript" type="text/javascript"></script><script src="../skin/getMenu.js" language="javascript" type="text/javascript"></script><script src="../skin/fontsize.js" language="javascript" type="text/javascript"></script>
-<link rel="shortcut icon" href="../">
-</head>
-<body onload="init()">
-<script type="text/javascript">ndeSetTextSize();</script>
-<div id="top">
-<!--+
-    |header
-    +-->
-<div class="header">
-<!--+
-    |start group logo
-    +-->
-<div class="grouplogo">
-<a href="http://xmlgraphics.apache.org/"><img class="logoImage" alt="Apache XML Graphics" src="../images/group-logo.gif" title="Apache XML Graphics is responsible for the creation and maintenance of software for managing the conversion of XML formats to graphical output, and the creation and maintenance of related software components, based on software licensed to the Foundation"></a>
-</div>
-<!--+
-    |end group logo
-    +-->
-<!--+
-    |start Project Logo
-    +-->
-<div class="projectlogo">
-<a href="http://xmlgraphics.apache.org/fop/"><img class="logoImage" alt="Apache FOP" src="../images/logo.jpg" title="Apache FOP (Formatting Objects Processor) is the world's first output independent formatter. Output formats currently supported include PDF, PCL, PS, SVG, XML (area tree representation), Print, AWT, MIF and TXT. The primary output target is PDF."></a>
-</div>
-<!--+
-    |end Project Logo
-    +-->
-<!--+
-    |start Search
-    +-->
-<div class="searchbox">
-<form action="http://www.google.com/search" method="get" class="roundtopsmall">
-<input value="xmlgraphics.apache.org" name="sitesearch" type="hidden"><input onFocus="getBlank (this, 'Search the site with google');" size="25" name="q" id="query" type="text" value="Search the site with google">&nbsp; 
-                    <input name="Search" value="Search" type="submit">
-</form>
-</div>
-<!--+
-    |end search
-    +-->
-<!--+
-    |start Tabs
-    +-->
-<ul id="tabs">
-<li>
-<a class="unselected" href="../index.html">Home</a>
-</li>
-<li>
-<a class="unselected" href="../0.94/index.html">Version 0.94</a>
-</li>
-<li>
-<a class="unselected" href="../0.95/index.html">Version 0.95</a>
-</li>
-<li class="current">
-<a class="selected" href="../trunk/index.html">FOP Trunk</a>
-</li>
-<li>
-<a class="unselected" href="../dev/index.html">Development</a>
-</li>
-</ul>
-<!--+
-    |end Tabs
-    +-->
-</div>
-</div>
-<div id="main">
-<div id="publishedStrip">
-<!--+
-    |start Subtabs
-    +-->
-<div id="level2tabs"></div>
-<!--+
-    |end Endtabs
-    +-->
-<script type="text/javascript"><!--
-document.write("Last Published: " + document.lastModified);
-//  --></script>
-</div>
-<!--+
-    |breadtrail
-    +-->
-<div class="breadtrail">
-<a href="http://www.apache.org/">apache.org</a> &gt; <a href="http://xml.apache.org/">XML Federation</a> &gt; <a href="http://xmlgraphics.apache.org/">xmlgraphics.apache.org</a><script src="../skin/breadcrumbs.js" language="JavaScript" type="text/javascript"></script>
-</div>
-<!--+
-    |start Menu, mainarea
-    +-->
-<!--+
-    |start Menu
-    +-->
-<div id="menu">
-<div onclick="SwitchMenu('menu_selected_1.1', '../skin/')" id="menu_selected_1.1Title" class="menutitle" style="background-image: url('../skin/images/chapter_open.gif');">FOP Trunk (dev)</div>
-<div id="menu_selected_1.1" class="selectedmenuitemgroup" style="display: block;">
-<div class="menuitem">
-<a href="../trunk/index.html">About</a>
-</div>
-<div class="menuitem">
-<a href="../trunk/upgrading.html">Upgrading</a>
-</div>
-<div onclick="SwitchMenu('menu_selected_1.1.3', '../skin/')" id="menu_selected_1.1.3Title" class="menutitle" style="background-image: url('../skin/images/chapter_open.gif');">Using FOP</div>
-<div id="menu_selected_1.1.3" class="selectedmenuitemgroup" style="display: block;">
-<div class="menuitem">
-<a href="../trunk/compiling.html">Build</a>
-</div>
-<div class="menuitem">
-<a href="../trunk/configuration.html">Configure</a>
-</div>
-<div class="menuitem">
-<a href="../trunk/running.html">Run</a>
-</div>
-<div class="menupage">
-<div class="menupagetitle">Embed</div>
-</div>
-<div class="menuitem">
-<a href="../trunk/servlets.html">Servlets</a>
-</div>
-<div class="menuitem">
-<a href="../trunk/anttask.html">Ant Task</a>
-</div>
-</div>
-<div onclick="SwitchMenu('menu_1.1.4', '../skin/')" id="menu_1.1.4Title" class="menutitle">Features</div>
-<div id="menu_1.1.4" class="menuitemgroup">
-<div class="menuitem">
-<a href="../trunk/output.html">Output Targets</a>
-</div>
-<div class="menuitem">
-<a href="../trunk/intermediate.html">Intermediate Format</a>
-</div>
-<div class="menuitem">
-<a href="../trunk/pdfencryption.html">PDF Encryption</a>
-</div>
-<div class="menuitem">
-<a href="../trunk/pdfa.html">PDF/A</a>
-</div>
-<div class="menuitem">
-<a href="../trunk/pdfx.html">PDF/X</a>
-</div>
-<div class="menuitem">
-<a href="../trunk/graphics.html">Graphics</a>
-</div>
-<div class="menuitem">
-<a href="../trunk/fonts.html">Fonts</a>
-</div>
-<div class="menuitem">
-<a href="../trunk/hyphenation.html">Hyphenation</a>
-</div>
-<div class="menuitem">
-<a href="../trunk/extensions.html">Extensions</a>
-</div>
-<div class="menuitem">
-<a href="../trunk/events.html">Events</a>
-</div>
-<div class="menuitem">
-<a href="../trunk/metadata.html">Metadata</a>
-</div>
-<div class="menuitem">
-<a href="../trunk/accessibility.html">Accessibility</a>
-</div>
-</div>
-</div>
-<div id="credit"></div>
-<div id="roundbottom">
-<img style="display: none" class="corner" height="15" width="15" alt="" src="../skin/images/rc-b-l-15-1body-2menu-3menu.png"></div>
-<!--+
-  |alternative credits
-  +-->
-<div id="credit2">
-<a href="http://us.apachecon.com/"><img border="0" title="ApacheCon US 2009" alt="ApacheCon US 2009 - logo" src="http://apache.org/ads/ApacheCon/2009-usa-125x125.png" style="width: 125px;height: 125px;"></a>
-</div>
-</div>
-<!--+
-    |end Menu
-    +-->
-<!--+
-    |start content
-    +-->
-<div id="content">
-<div title="raw XML" class="xmllink">
-<a class="dida" href="embedding.xml"><img alt="XML - icon" src="../skin/images/xmldoc.gif" class="skin"><br>
-        XML</a>
-</div>
-<div title="Portable Document Format" class="pdflink">
-<a class="dida" href="embedding.pdf"><img alt="PDF -icon" src="../skin/images/pdfdoc.gif" class="skin"><br>
-        PDF</a>
-</div>
-<div class="trail">Font size: 
-	          &nbsp;<input value="Reset" class="resetfont" title="Reset text" onclick="ndeSetTextSize('reset'); return false;" type="button">      
-	          &nbsp;<input value="-a" class="smallerfont" title="Shrink text" onclick="ndeSetTextSize('decr'); return false;" type="button">
-	          &nbsp;<input value="+a" class="biggerfont" title="Enlarge text" onclick="ndeSetTextSize('incr'); return false;" type="button">
-</div>
-<h1>Apache FOP: Embedding</h1>
-<h3>How to Embed FOP in a Java application</h3>
-<div id="front-matter">
-<div id="minitoc-area">
-<ul class="minitoc">
-<li>
-<a href="#overview">Overview</a>
-</li>
-<li>
-<a href="#basics">Basic Usage Pattern</a>
-<ul class="minitoc">
-<li>
-<a href="#basic-logging">Logging</a>
-</li>
-<li>
-<a href="#render">Processing XSL-FO</a>
-</li>
-<li>
-<a href="#render-with-xslt">Processing XSL-FO generated from XML+XSLT</a>
-</li>
-</ul>
-</li>
-<li>
-<a href="#input">Input Sources</a>
-</li>
-<li>
-<a href="#config-internal">Configuring Apache FOP Programmatically</a>
-<ul class="minitoc">
-<li>
-<a href="#fop-factory">Customizing the FopFactory</a>
-</li>
-<li>
-<a href="#user-agent">Customizing the User Agent</a>
-</li>
-</ul>
-</li>
-<li>
-<a href="#config-external">Using a Configuration File</a>
-</li>
-<li>
-<a href="#hints">Hints</a>
-<ul class="minitoc">
-<li>
-<a href="#object-reuse">Object reuse</a>
-</li>
-<li>
-<a href="#awt">AWT issues</a>
-</li>
-<li>
-<a href="#render-info">Getting information on the rendering process</a>
-</li>
-</ul>
-</li>
-<li>
-<a href="#performance">Improving performance</a>
-</li>
-<li>
-<a href="#multithreading">Multithreading FOP</a>
-</li>
-<li>
-<a href="#examples">Examples</a>
-<ul class="minitoc">
-<li>
-<a href="#ExampleFO2PDF">ExampleFO2PDF.java</a>
-</li>
-<li>
-<a href="#ExampleXML2FO">ExampleXML2FO.java</a>
-</li>
-<li>
-<a href="#ExampleXML2PDF">ExampleXML2PDF.java</a>
-</li>
-<li>
-<a href="#ExampleObj2XML">ExampleObj2XML.java</a>
-</li>
-<li>
-<a href="#ExampleObj2PDF">ExampleObj2PDF.java</a>
-</li>
-<li>
-<a href="#ExampleDOM2PDF">ExampleDOM2PDF.java</a>
-</li>
-<li>
-<a href="#ExampleSVG2PDF">ExampleSVG2PDF.java (PDF Transcoder example)</a>
-</li>
-<li>
-<a href="#example-notes">Final notes</a>
-</li>
-</ul>
-</li>
-</ul>
-</div>
-</div>
-  
-<a name="N10015"></a><a name="overview"></a>
-<h2 class="underlined_10">Overview</h2>
-<div class="section">
-<p>
-      Review <a href="running.html">Running FOP</a> for important information that applies 
-      to embedded applications as well as command-line use, such as options and performance.
-    </p>
-<p>
-      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.
-    </p>
-<div class="note">
-<div class="label">Note</div>
-<div class="content">
-      We recently changed FOP's outer API to what we consider the final API. This might require
-      some changes in your application. The main reasons for these changes were performance
-      improvements due to better reuse of reusable objects and reduced use of static variables
-      for added flexibility in complex environments.
-    </div>
-</div>
-</div>
-  
-<a name="N10029"></a><a name="basics"></a>
-<h2 class="underlined_10">Basic Usage Pattern</h2>
-<div class="section">
-<p>
-      Apache FOP relies heavily on JAXP. It uses SAX events exclusively to receive the XSL-FO 
-      input document. It is therefore a good idea that you know a few things about JAXP (which
-      is a good skill anyway). Let's look at the basic usage pattern for FOP...
-    </p>
-<p>Here is the basic pattern to render an XSL-FO file to PDF:
-    </p>
-<pre class="code">
-import org.apache.fop.apps.FopFactory;
-import org.apache.fop.apps.Fop;
-import org.apache.fop.apps.MimeConstants;
-
-/*..*/
-
-// Step 1: Construct a FopFactory
-// (reuse if you plan to render multiple documents!)
-FopFactory fopFactory = FopFactory.newInstance();
-
-// Step 2: Set up output stream.
-// Note: Using BufferedOutputStream for performance reasons (helpful with FileOutputStreams).
-OutputStream out = new BufferedOutputStream(new FileOutputStream(new File("C:/Temp/myfile.pdf")));
-
-try {
-  // Step 3: Construct fop with desired output format
-  Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, out);
-
-  // Step 4: Setup JAXP using identity transformer
-  TransformerFactory factory = TransformerFactory.newInstance();
-  Transformer transformer = factory.newTransformer(); // identity transformer
-           
-  // Step 5: Setup input and output for XSLT transformation 
-  // Setup input stream
-  Source src = new StreamSource(new File("C:/Temp/myfile.fo"));
-
-  // Resulting SAX events (the generated FO) must be piped through to FOP
-  Result res = new SAXResult(fop.getDefaultHandler());
-            
-  // Step 6: Start XSLT transformation and FOP processing
-  transformer.transform(src, res);
-
-} finally {
-  //Clean-up
-  out.close();
-}</pre>
-<p>
-      Let's discuss these 5 steps in detail:
-    </p>
-<ul>
-      
-<li>
-        
-<strong>Step 1:</strong> You create a new FopFactory instance. The FopFactory instance holds 
-        references to configuration information and cached data. It's important to reuse this
-        instance if you plan to render multiple documents during a JVM's lifetime.
-      </li>
-      
-<li>
-        
-<strong>Step 2:</strong> You set up an OutputStream that the generated document
-        will be written to. It's a good idea to buffer the OutputStream as demonstrated 
-        to improve performance.
-      </li>
-      
-<li>
-        
-<strong>Step 3:</strong> You create a new Fop instance through one of the factory
-        methods on the FopFactory. You tell the FopFactory what your desired output format
-        is. This is done by using the MIME type of the desired output format (ex. "application/pdf").
-        You can use one of the MimeConstants.* constants. The second parameter is the
-        OutputStream you've setup up in step 2.
-      </li>
-      
-<li>
-        
-<strong>Step 4</strong> We recommend that you use JAXP Transformers even 
-        if you don't do XSLT transformations to generate the XSL-FO file. This way 
-        you can always use the same basic pattern. The example here sets up an 
-        "identity transformer" which just passes the input (Source) unchanged to the 
-        output (Result). You don't have to work with a SAXParser if you don't do any 
-        XSLT transformations.
-      </li>
-      
-<li>
-        
-<strong>Step 5:</strong> Here you set up the input and output for the XSLT 
-        transformation. The Source object is set up to load the "myfile.fo" file. 
-        The Result is set up so the output of the XSLT transformation is sent to FOP. 
-        The FO file is sent to FOP in the form of SAX events which is the most efficient 
-        way. Please always avoid saving intermediate results to a file or a memory buffer 
-        because that affects performance negatively.
-      </li>
-      
-<li>
-        
-<strong>Step 6:</strong> Finally, we start the XSLT transformation by starting 
-        the JAXP Transformer. As soon as the JAXP Transformer starts to send its output 
-        to FOP, FOP itself starts its processing in the background. When the 
-        <span class="codefrag">transform()</span> method returns FOP will also have finished converting 
-        the FO file to a PDF file and you can close the OutputStream.
-        <div class="note">
-<div class="label">Tip!</div>
-<div class="content">
-          It's a good idea to enclose the whole conversion in a try..finally statement. If
-          you close the OutputStream in the finally section, this will make sure that the
-          OutputStream is properly closed even if an exception occurs during the conversion.
-        </div>
-</div>
-      
-</li>
-    
-</ul>
-<p>
-      If you're not totally familiar with JAXP Transformers, please have a look at the 
-      <a href="#examples">Embedding examples</a> below. The section contains examples
-      for all sorts of use cases. If you look at all of them in turn you should be able
-      to see the patterns in use and the flexibility this approach offers without adding
-      too much complexity.
-    </p>
-<p>
-      This may look complicated at first, but it's really just the combination of an 
-      XSL transformation and a FOP run. It's also easy to comment out the FOP part
-      for debugging purposes, for example when you're tracking down a bug in your 
-      stylesheet. You can easily write the XSL-FO output from the XSL transformation
-      to a file to check if that part generates the expected output. An example for that
-      can be found in the <a href="#examples">Embedding examples</a> (See "ExampleXML2FO").
-    </p>
-<a name="N10078"></a><a name="basic-logging"></a>
-<h3 class="underlined_5">Logging</h3>
-<p>
-        Logging is now a little different than it was in FOP 0.20.5. We've switched from
-        Avalon Logging to <a class="external" href="http://commons.apache.org/logging/">Jakarta Commons Logging</a>.
-        While with Avalon Logging the loggers were directly given to FOP, FOP now retrieves
-        its logger(s) through a statically available LogFactory. This is similar to the
-        general pattern that you use when you work with Apache Log4J directly, for example.
-        We call this "static logging" (Commons Logging, Log4J) as opposed to "instance logging" 
-        (Avalon Logging). This has a consequence: You can't give FOP a logger for each
-        processing run anymore. The log output of multiple, simultaneously running FOP instances
-        is sent to the same logger.
-      </p>
-<p>
-        By default, <a class="external" href="http://commons.apache.org/logging/">Jakarta Commons Logging</a> uses
-        JDK logging (available in JDKs 1.4 or higher) as its backend. You can configure Commons
-        Logging to use an alternative backend, for example Log4J. Please consult the
-        <a class="external" href="http://commons.apache.org/logging/">documentation for Jakarta Commons Logging</a> on
-        how to configure alternative backends.
-      </p>
-<p>
-        As a result of the above we differentiate between two kinds of "logging":
-      </p>
-<ul>
-        
-<li>(FOP-)Developer-oriented logging</li>
-        
-<li>
-<a href="events.html">User/Integrator-oriented feedback</a> (NEW!)</li>
-      
-</ul>
-<p>
-        The use of "feedback" instead of "logging" is intentional. Most people were using
-        log output as a means to get feedback from events within FOP. Therefore, FOP now
-        includes an <span class="codefrag">event</span> package which can be used to receive feedback from
-        the layout engine and other components within FOP <strong>per rendering run</strong>.
-        This feedback is not just some
-        text but event objects with parameters so these events can be interpreted by code.
-        Of course, there is a facility to turn these events into normal human-readable
-        messages. For details, please read on on the <a href="events.html">Events page</a>.
-        This leaves normal logging to be mostly a thing used by the FOP developers
-        although anyone can surely activate certain logging categories but the feedback
-        from the loggers won't be separated by processing runs. If this is required,
-        the <a href="events.html">Events subsystem</a> is the right approach.
-      </p>
-<a name="N100B1"></a><a name="render"></a>
-<h3 class="underlined_5">Processing XSL-FO</h3>
-<p>
-        Once the Fop instance is set up, call <span class="codefrag">getDefaultHandler()</span> 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
-        <span class="codefrag">startDocument()</span> method is called. Processing stops again when the
-        DefaultHandler's <span class="codefrag">endDocument()</span> method is called. Please refer to the basic
-        usage pattern shown above to render a simple XSL-FO document.
-      </p>
-<a name="N100C4"></a><a name="render-with-xslt"></a>
-<h3 class="underlined_5">Processing XSL-FO generated from XML+XSLT</h3>
-<p>
-        If you want to process XSL-FO generated from XML using XSLT we recommend 
-        again using standard JAXP to do the XSLT part and piping the generated SAX 
-        events directly through to FOP. The only thing you'd change to do that 
-        on the basic usage pattern above is to set up the Transformer differently:
-      </p>
-<pre class="code">
-  //without XSLT:
-  //Transformer transformer = factory.newTransformer(); // identity transformer
-  
-  //with XSLT:
-  Source xslt = new StreamSource(new File("mystylesheet.xsl"));
-  Transformer transformer = factory.newTransformer(xslt);</pre>
-</div>
-  
-<a name="N100D3"></a><a name="input"></a>
-<h2 class="underlined_10">Input Sources</h2>
-<div class="section">
-<p>
-      The input XSL-FO document is always received by FOP as a SAX stream (see the 
-      <a href="../dev/design/parsing.html">Parsing Design Document</a> for the rationale).
-    </p>
-<p>
-      However, you may not always have your input document available as a SAX stream. 
-      But with JAXP it's easy to convert different input sources to a SAX stream so you
-      can pipe it into FOP. That sounds more difficult than it is. You simply have
-      to set up the right Source instance as input for the JAXP transformation. 
-      A few examples:
-    </p>
-<ul>
-      
-<li>
-        
-<strong>URL:</strong> <span class="codefrag">Source src = new StreamSource("http://localhost:8080/testfile.xml");</span>
-      
-</li>
-      
-<li>
-        
-<strong>File:</strong> <span class="codefrag">Source src = new StreamSource(new File("C:/Temp/myinputfile.xml"));</span>
-      
-</li>
-      
-<li>
-        
-<strong>String:</strong> <span class="codefrag">Source src = new StreamSource(new StringReader(myString)); // myString is a String</span>
-      
-</li>
-      
-<li>
-        
-<strong>InputStream:</strong> <span class="codefrag">Source src = new StreamSource(new MyInputStream(something));</span>
-      
-</li>
-      
-<li>
-        
-<strong>Byte Array:</strong> <span class="codefrag">Source src = new StreamSource(new ByteArrayInputStream(myBuffer)); // myBuffer is a byte[] here</span>
-      
-</li>
-      
-<li>
-        
-<strong>DOM:</strong> <span class="codefrag">Source src = new DOMSource(myDocument); // myDocument is a Document or a Node</span>
-      
-</li>
-      
-<li>
-        
-<strong>Java Objects:</strong> Please have a look at the <a href="#examples">Embedding examples</a> which contain an example for this.
-      </li>
-    
-</ul>
-<p>
-      There are a variety of upstream data manipulations possible.
-      For example, you may have a DOM and an XSL stylesheet; or you may want to
-      set variables in the stylesheet. Interface documentation and some cookbook 
-      solutions to these situations are provided in 
-      <a class="external" href="http://xml.apache.org/xalan-j/usagepatterns.html">Xalan Basic Usage Patterns</a>.
-    </p>
-</div>
-  
-<a name="N1012E"></a><a name="config-internal"></a>
-<h2 class="underlined_10">Configuring Apache FOP Programmatically</h2>
-<div class="section">
-<p>
-      Apache FOP provides two levels on which you can customize FOP's
-      behaviour: the FopFactory and the user agent.
-    </p>
-<a name="N10137"></a><a name="fop-factory"></a>
-<h3 class="underlined_5">Customizing the FopFactory</h3>
-<p>
-        The FopFactory holds configuration data and references to objects which are reusable over
-        multiple rendering runs. It's important to instantiate it only once (except in special 
-        environments) and reuse it every time to create new FOUserAgent and Fop instances.
-      </p>
-<p>
-        You can set all sorts of things on the FopFactory:
-      </p>
-<ul>
-        
-<li>
-          
-<p>
-            The <strong>font base URL</strong> to use when resolving relative URLs for fonts. Example:
-          </p>
-          
-<pre class="code">fopFactory.setFontBaseURL("file:///C:/Temp/fonts");</pre>
-        
-</li>
-        
-<li>
-          
-<p>
-            The <strong>hyphenation base URL</strong> to use when resolving relative URLs for 
-            hyphenation patterns. Example:
-          </p>
-          
-<pre class="code">fopFactory.setHyphenBaseURL("file:///C:/Temp/hyph");</pre>
-        
-</li>
-        
-<li>
-          
-<p>
-            Disable <strong>strict validation</strong>. When disabled FOP is less strict about the rules 
-            established by the XSL-FO specification. Example:
-          </p>
-          
-<pre class="code">fopFactory.setStrictValidation(false);</pre>
-        
-</li>
-        
-<li>
-          
-<p>
-            Enable an <strong>alternative set of rules for text indents</strong> that tries to mimic the behaviour of many commercial 
-            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:
-          </p>
-          
-<pre class="code">fopFactory.setBreakIndentInheritanceOnReferenceAreaBoundary(true);</pre>
-        
-</li>
-        
-<li>
-          
-<p>
-            Set the <strong>source resolution</strong> 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:
-          </p>
-          
-<pre class="code">fopFactory.setSourceResolution(96); // =96dpi (dots/pixels per Inch)</pre>
-        
-</li>
-        
-<li>
-          
-<p>
-            Manually add an <strong>ElementMapping instance</strong>. 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). Example:
-          </p>
-          
-<pre class="code">fopFactory.addElementMapping(myElementMapping); // myElementMapping is a org.apache.fop.fo.ElementMapping</pre>
-        
-</li>
-        
-<li>
-          
-<p>
-            Set a <strong>URIResolver</strong> for custom URI resolution. By supplying a JAXP URIResolver you can add
-            custom URI resolution functionality to FOP. For example, you can use 
-            <a class="external" href="http://xml.apache.org/commons/components/resolver/">Apache XML Commons Resolver</a> to make use of XCatalogs. Example:
-          </p>
-          
-<pre class="code">fopFactory.setURIResolver(myResolver); // myResolver is a javax.xml.transform.URIResolver</pre>
-          
-<div class="note">
-<div class="label">Note</div>
-<div class="content">
-            Both the FopFactory and the FOUserAgent have a method to set a URIResolver. The URIResolver on the FopFactory
-            is primarily used to resolve URIs on factory-level (hyphenation patterns, for example) and it is always used 
-            if no other URIResolver (for example on the FOUserAgent) resolved the URI first.
-          </div>
-</div>
-        
-</li>
-      
-</ul>
-<a name="N101A9"></a><a name="user-agent"></a>
-<h3 class="underlined_5">Customizing the User Agent</h3>
-<p>
-        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 appropriate factory method on FopFactory and pass that 
-        to the factory method that will create a new Fop instance:
-      </p>
-<pre class="code">
-  FopFactory fopFactory = FopFactory.newInstance(); // Reuse the FopFactory if possible!
-  // do the following for each new rendering run
-  FOUserAgent userAgent = fopFactory.newFOUserAgent();
-  // customize userAgent
-  Fop fop = fopFactory.newFop(MimeConstants.MIME_POSTSCRIPT, userAgent, out);</pre>
-<p>
-        You can do all sorts of things on the user agent:
-      </p>
-<ul>
-        
-<li>
-          
-<p>
-            The <strong>base URL</strong> to use when resolving relative URLs. Example:
-          </p>
-          
-<pre class="code">userAgent.setBaseURL("file:///C:/Temp/");</pre>
-        
-</li>
-        
-<li>
-          
-<p>
-            Set the <strong>producer</strong> of the document. This is metadata information that can be used for certain output formats such as PDF. The default producer is "Apache FOP". Example:
-          </p>
-          
-<pre class="code">userAgent.setProducer("MyKillerApplication");</pre>
-        
-</li>
-        
-<li>
-          
-<p>
-            Set the <strong>creating user</strong> of the document. This is metadata information that can be used for certain output formats such as PDF. Example:
-          </p>
-          
-<pre class="code">userAgent.setCreator("John Doe");</pre>
-        
-</li>
-        
-<li>
-          
-<p>
-            Set the <strong>author</strong> of the document. This is metadata information that can be used for certain output formats such as PDF. Example:
-          </p>
-          
-<pre class="code">userAgent.setAuthor("John Doe");</pre>
-        
-</li>
-        
-<li>
-          
-<p>
-            Override the <strong>creation date and time</strong> of the document. This is metadata information that can be used for certain output formats such as PDF. Example:
-          </p>
-          
-<pre class="code">userAgent.setCreationDate(new Date());</pre>
-        
-</li>
-        
-<li>
-          
-<p>
-            Set the <strong>title</strong> of the document. This is metadata information that can be used for certain output formats such as PDF. Example:
-          </p>
-          
-<pre class="code">userAgent.setTitle("Invoice No 138716847");</pre>
-        
-</li>
-        
-<li>
-          
-<p>
-            Set the <strong>keywords</strong> of the document. This is metadata information that can be used for certain output formats such as PDF. Example:
-          </p>
-          
-<pre class="code">userAgent.setKeywords("XML XSL-FO");</pre>
-        
-</li>
-        
-<li>
-          
-<p>
-            Set the <strong>target resolution</strong> for the document. This is used to 
-            specify the output resolution for bitmap images generated by bitmap renderers 
-            (such as the TIFF renderer) and by bitmaps generated by Apache Batik for filter 
-            effects and such. Default: 72 dpi. Example:
-          </p>
-          
-<pre class="code">userAgent.setTargetResolution(300); // =300dpi (dots/pixels per Inch)</pre>
-        
-</li>
-        
-<li>
-          
-<p>
-            Set <strong>your own Renderer instance</strong>. If you want to supply your own renderer or 
-            configure a Renderer in a special way you can give the instance to the FOUserAgent. Normally,
-            the Renderer instance is created by FOP. Example:
-          </p>
-          
-<pre class="code">userAgent.setRendererOverride(myRenderer); // myRenderer is an org.apache.fop.render.Renderer</pre>
-        
-</li>
-        
-<li>
-          
-<p>
-            Set <strong>your own FOEventHandler instance</strong>. If you want to supply your own FOEventHandler or 
-            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:
-          </p>
-          
-<pre class="code">userAgent.setFOEventHandlerOverride(myFOEventHandler); // myFOEventHandler is an org.apache.fop.fo.FOEventHandler</pre>
-        
-</li>
-        
-<li>
-          
-<p>
-            Set a <strong>URIResolver</strong> for custom URI resolution. By supplying a JAXP URIResolver you can add
-            custom URI resolution functionality to FOP. For example, you can use 
-            <a class="external" href="http://xml.apache.org/commons/components/resolver/">Apache XML Commons Resolver</a> to make use of XCatalogs. Example:
-          </p>
-          
-<pre class="code">userAgent.setURIResolver(myResolver); // myResolver is a javax.xml.transform.URIResolver</pre>
-          
-<div class="note">
-<div class="label">Note</div>
-<div class="content">
-            Both the FopFactory and the FOUserAgent have a method to set a URIResolver. The URIResolver on the FOUserAgent is
-            used for resolving URIs which are document-related. If it's not set or cannot resolve a URI, the URIResolver
-            from the FopFactory is used.
-          </div>
-</div>
-        
-</li>
-      
-</ul>
-<div class="note">
-<div class="label">Note</div>
-<div class="content">
-        You should not reuse an FOUserAgent instance between FOP rendering runs although you can. Especially
-        in multi-threaded environment, this is a bad idea.
-      </div>
-</div>
-</div>
-  
-<a name="N10257"></a><a name="config-external"></a>
-<h2 class="underlined_10">Using a Configuration File</h2>
-<div class="section">
-<p>
-      Instead of setting the parameters manually in code as shown above you can also set 
-      many values from an XML configuration file:
-    </p>
-<pre class="code">
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
-
-/*..*/
-
-DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder();
-Configuration cfg = cfgBuilder.buildFromFile(new File("C:/Temp/mycfg.xml"));
-fopFactory.setUserConfig(cfg);
-
-/* ..or.. */
-
-fopFactory.setUserConfig(new File("C:/Temp/mycfg.xml"));</pre>
-<p>
-      The layout of the configuration file is described on the <a href="configuration.html">Configuration page</a>.
-    </p>
-</div>
-  
-<a name="N1026C"></a><a name="hints"></a>
-<h2 class="underlined_10">Hints</h2>
-<div class="section">
-<a name="N10272"></a><a name="object-reuse"></a>
-<h3 class="underlined_5">Object reuse</h3>
-<p>
-        Fop instances shouldn't (and can't) be reused. Please recreate
-        Fop and FOUserAgent instances for each rendering run using the FopFactory.
-        This is a cheap operation as all reusable information is held in the 
-        FopFactory. That's why it's so important to reuse the FopFactory instance.
-     </p>
-<a name="N1027C"></a><a name="awt"></a>
-<h3 class="underlined_5">AWT issues</h3>
-<p>
-        If your XSL-FO files contain SVG then Apache Batik will be used. When Batik is
-        initialised it uses certain classes in <span class="codefrag">java.awt</span> that
-        intialise the Java AWT classes. This means that a daemon thread
-        is created by the JVM and on Unix it will need to connect to a
-        DISPLAY.
-      </p>
-<p>
-        The thread means that the Java application may not automatically quit
-        when finished, you will need to call <span class="codefrag">System.exit()</span>. These
-        issues should be fixed in the JDK 1.4.
-      </p>
-<p>
-        If you run into trouble running FOP on a head-less server, please see the
-        <a href="graphics.html#batik">notes on Batik</a>.
-      </p>
-<a name="N10296"></a><a name="render-info"></a>
-<h3 class="underlined_5">Getting information on the rendering process</h3>
-<p>
-        To get the number of pages that were rendered by FOP you can call 
-        <span class="codefrag">Fop.getResults()</span>. This returns a <span class="codefrag">FormattingResults</span> object 
-        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 
-        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.
-      </p>
-</div>
-  
-<a name="N102A7"></a><a name="performance"></a>
-<h2 class="underlined_10">Improving performance</h2>
-<div class="section">
-<p>
-      There are several options to consider:
-    </p>
-<ul>
-      
-<li>
-        Whenever possible, try to use SAX to couple the individual components involved 
-        (parser, XSL transformer, SQL datasource etc.).
-      </li>
-      
-<li>
-        Depending on the target OutputStream (in case of a FileOutputStream, but not 
-        for a ByteArrayOutputStream, for example) it may improve performance considerably 
-        if you buffer the OutputStream using a BufferedOutputStream: 
-        <span class="codefrag">out = new java.io.BufferedOutputStream(out);</span>
-        
-<br>
-        Make sure you properly close the OutputStream when FOP is finished.
-      </li>
-      
-<li>
-        Cache the stylesheet. If you use the same stylesheet multiple times 
-        you can set up a JAXP <span class="codefrag">Templates</span> object and reuse it each time you do
-        the XSL transformation.  (More information can be found
-        <a class="external" href="http://www.javaworld.com/javaworld/jw-05-2003/jw-0502-xsl.html">here</a>.)
-      </li>
-      
-<li>
-        Use an XSLT compiler like <a class="external" href="http://xml.apache.org/xalan-j/xsltc_usage.html">XSLTC</a>
-        that comes with Xalan-J.
-      </li>
-      
-<li>
-        Fine-tune your stylesheet to make the XSLT process more efficient and to create XSL-FO that can
-        be processed by FOP more efficiently. Less is more: Try to make use of property inheritance where possible.
-      </li>
-      
-<li>
-        You may also wish to consider trying to reduce <a href="http://xmlgraphics.apache.org/fop/trunk/running.html#memory">memory usage</a>.
-      </li>
-    
-</ul>
-</div>
-  
-<a name="N102DC"></a><a name="multithreading"></a>
-<h2 class="underlined_10">Multithreading FOP</h2>
-<div class="section">
-<p>
-      Apache FOP may currently not be completely thread safe.
-      The code has not been fully tested for multi-threading issues, yet.
-      If you encounter any suspicious behaviour, please notify us.
-    </p>
-<p>
-      There is also a known issue with fonts being jumbled between threads when using 
-      the Java2D/AWT renderer (which is used by the -awt and -print output options).
-      In general, you cannot safely run multiple threads through the AWT renderer.
-    </p>
-</div>
-
-<a name="N102E9"></a><a name="examples"></a>
-<h2 class="underlined_10">Examples</h2>
-<div class="section">
-<p>
-   The directory "{fop-dir}/examples/embedding" contains several working examples. 
-  </p>
-<a name="N102F2"></a><a name="ExampleFO2PDF"></a>
-<h3 class="underlined_5">ExampleFO2PDF.java</h3>
-<p>This
-        <a class="external" href="http://svn.apache.org/viewcvs.cgi/xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleFO2PDF.java?view=markup">
-            example</a>
-demonstrates the basic usage pattern to transform an XSL-FO
-file to PDF using FOP.
-    </p>
-<div id="" style="text-align: center;">
-<img id="" class="figure" alt="Example XSL-FO to PDF" src="images/EmbeddingExampleFO2PDF.png"></div>
-<a name="N10304"></a><a name="ExampleXML2FO"></a>
-<h3 class="underlined_5">ExampleXML2FO.java</h3>
-<p>This 
-        <a class="external" href="http://svn.apache.org/viewcvs.cgi/xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleXML2FO.java?view=markup">
-            example</a>
-has nothing to do with FOP. It is there to show you how an XML 
-file can be converted to XSL-FO using XSLT. The JAXP API is used to do the
-transformation. Make sure you've got a JAXP-compliant XSLT processor in your 
-classpath (ex. <a class="external" href="http://xml.apache.org/xalan-j">Xalan</a>).
-    </p>
-<div id="" style="text-align: center;">
-<img id="" class="figure" alt="Example XML to XSL-FO" src="images/EmbeddingExampleXML2FO.png"></div>
-<a name="N1031A"></a><a name="ExampleXML2PDF"></a>
-<h3 class="underlined_5">ExampleXML2PDF.java</h3>
-<p>This 
-        <a class="external" href="http://svn.apache.org/viewcvs.cgi/xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleXML2PDF.java?view=markup">
-        example</a>
-demonstrates how you can convert an arbitrary XML file to PDF 
-using XSLT and XSL-FO/FOP. It is a combination of the first two examples 
-above. The example uses JAXP to transform the XML file to XSL-FO and FOP to 
-transform the XSL-FO to PDF.
-    </p>
-<div id="" style="text-align: center;">
-<img id="" class="figure" alt="Example XML to PDF (via XSL-FO)" src="images/EmbeddingExampleXML2PDF.png"></div>
-<p>
-The output (XSL-FO) from the XSL transformation is piped through to FOP using 
-SAX events. This is the most efficient way to do this because the 
-intermediate result doesn't have to be saved somewhere. Often, novice users 
-save the intermediate result in a file, a byte array or a DOM tree. We 
-strongly discourage you to do this if it isn't absolutely necessary. The 
-performance is significantly higher with SAX.
-    </p>
-<a name="N1032F"></a><a name="ExampleObj2XML"></a>
-<h3 class="underlined_5">ExampleObj2XML.java</h3>
-<p>This 
-    <a class="external" href="http://svn.apache.org/viewcvs.cgi/xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleObj2XML.java?view=markup">
-        example</a>
-is a preparatory example for the next one. It's an example that 
-shows how an arbitrary Java object can be converted to XML. It's an often 
-needed task to do this. Often people create a DOM tree from a Java object and 
-use that. This is pretty straightforward. The example here, however, shows how
-to do this using SAX, which will probably be faster and not even more 
-complicated once you know how this works.
-    </p>
-<div id="" style="text-align: center;">
-<img id="" class="figure" alt="Example Java object to XML" src="images/EmbeddingExampleObj2XML.png"></div>
-<p>
-For this example we've created two classes: ProjectTeam and ProjectMember 
-(found in xml-fop/examples/embedding/java/embedding/model). They represent 
-the same data structure found in 
-xml-fop/examples/embedding/xml/xml/projectteam.xml. We want to serialize to XML a 
-project team with several members which exist as Java objects. 
-Therefore we created the two classes: ProjectTeamInputSource and 
-ProjectTeamXMLReader (in the same place as ProjectTeam above).
-    </p>
-<p>
-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.
-    </p>
-<p>
-Have a look at the source of ExampleObj2XML.java to find out how this is 
-used. For more detailed information see other resources on JAXP (ex. 
-<a class="external" href="http://java.sun.com/xml/jaxp/dist/1.1/docs/tutorial/xslt/3_generate.html">An older JAXP tutorial</a>).
-    </p>
-<a name="N1034F"></a><a name="ExampleObj2PDF"></a>
-<h3 class="underlined_5">ExampleObj2PDF.java</h3>
-<p>This 
-        <a class="external" href="http://svn.apache.org/viewcvs.cgi/xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleObj2PDF.java?view=markup">
-            example</a>
-combines the previous and the third to demonstrate 
-how you can transform a Java object to a PDF directly in one smooth run
-by generating SAX events from the Java object that get fed to an XSL 
-transformation. The result of the transformation is then converted to PDF 
-using FOP as before.
-    </p>
-<div id="" style="text-align: center;">
-<img id="" class="figure" alt="Example Java object to PDF (via XML and XSL-FO)" src="images/EmbeddingExampleObj2PDF.png"></div>
-<a name="N10361"></a><a name="ExampleDOM2PDF"></a>
-<h3 class="underlined_5">ExampleDOM2PDF.java</h3>
-<p>This 
-        <a class="external" href="http://svn.apache.org/viewcvs.cgi/xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleDOM2PDF.java?view=markup">
-            example</a>
-has FOP use a DOMSource instead of a StreamSource in order to 
-use a DOM tree as input for an XSL transformation.
-    </p>
-<a name="N1036F"></a><a name="ExampleSVG2PDF"></a>
-<h3 class="underlined_5">ExampleSVG2PDF.java (PDF Transcoder example)</h3>
-<p>This 
-        <a class="external" href="http://svn.apache.org/viewcvs.cgi/xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleSVG2PDF.java?view=markup">
-            example</a>
-shows the usage of the PDF Transcoder, a sub-application within FOP.  
-It is used to generate a PDF document from an SVG file.
-    </p>
-<a name="N1037D"></a><a name="example-notes"></a>
-<h3 class="underlined_5">Final notes</h3>
-<p>
-These examples should give you an idea of what's possible. It should be easy 
-to adjust these examples to your needs. Also, if you have other examples that you
-think should be added here, please let us know via either the fop-users or fop-dev
-mailing lists.  Finally, for more help please send your questions to the fop-users
-mailing list.
-    </p>
-</div>
-  
-<span class="version">
-          version 772147</span>
-</div>
-<!--+
-    |end content
-    +-->
-<div class="clearboth">&nbsp;</div>
-</div>
-<div id="footer">
-<!--+
-    |start bottomstrip
-    +-->
-<div class="lastmodified">
-<script type="text/javascript"><!--
-document.write("Last Published: " + document.lastModified);
-//  --></script>
-</div>
-<div class="copyright">
-        Copyright &copy;
-         1999-2009 <a href="http://www.apache.org/licenses/">The Apache Software Foundation.</a>
-</div>
-<!--+
-    |end bottomstrip
-    +-->
-</div>
-</body>
-</html>
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head>
+<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
+<meta content="Apache Forrest" name="Generator">
+<meta name="Forrest-version" content="0.9-dev">
+<meta name="Forrest-skin-name" content="pelt">
+<title>Apache FOP: Embedding</title>
+<link type="text/css" href="../skin/basic.css" rel="stylesheet">
+<link media="screen" type="text/css" href="../skin/screen.css" rel="stylesheet">
+<link media="print" type="text/css" href="../skin/print.css" rel="stylesheet">
+<link type="text/css" href="../skin/profile.css" rel="stylesheet">
+<script src="../skin/getBlank.js" language="javascript" type="text/javascript"></script><script src="../skin/getMenu.js" language="javascript" type="text/javascript"></script><script src="../skin/fontsize.js" language="javascript" type="text/javascript"></script>
+<link rel="shortcut icon" href="../">
+</head>
+<body onload="init()">
+<script type="text/javascript">ndeSetTextSize();</script>
+<div id="top">
+<!--+
+    |header
+    +-->
+<div class="header">
+<!--+
+    |start group logo
+    +-->
+<div class="grouplogo">
+<a href="http://xmlgraphics.apache.org/"><img class="logoImage" alt="Apache XML Graphics" src="../images/group-logo.gif" title="Apache XML Graphics is responsible for the creation and maintenance of software for managing the conversion of XML formats to graphical output, and the creation and maintenance of related software components, based on software licensed to the Foundation"></a>
+</div>
+<!--+
+    |end group logo
+    +-->
+<!--+
+    |start Project Logo
+    +-->
+<div class="projectlogo">
+<a href="http://xmlgraphics.apache.org/fop/"><img class="logoImage" alt="Apache FOP" src="../images/logo.jpg" title="Apache FOP (Formatting Objects Processor) is the world's first output independent formatter. Output formats currently supported include PDF, PCL, PS, SVG, XML (area tree representation), Print, AWT, MIF and TXT. The primary output target is PDF."></a>
+</div>
+<!--+
+    |end Project Logo
+    +-->
+<!--+
+    |start Search
+    +-->
+<div class="searchbox">
+<form action="http://www.google.com/search" method="get" class="roundtopsmall">
+<input value="xmlgraphics.apache.org" name="sitesearch" type="hidden"><input onFocus="getBlank (this, 'Search the site with google');" size="25" name="q" id="query" type="text" value="Search the site with google">&nbsp; 
+                    <input name="Search" value="Search" type="submit">
+</form>
+</div>
+<!--+
+    |end search
+    +-->
+<!--+
+    |start Tabs
+    +-->
+<ul id="tabs">
+<li>
+<a class="unselected" href="../index.html">Home</a>
+</li>
+<li>
+<a class="unselected" href="../0.94/index.html">Version 0.94</a>
+</li>
+<li>
+<a class="unselected" href="../0.95/index.html">Version 0.95</a>
+</li>
+<li class="current">
+<a class="selected" href="../trunk/index.html">FOP Trunk</a>
+</li>
+<li>
+<a class="unselected" href="../dev/index.html">Development</a>
+</li>
+</ul>
+<!--+
+    |end Tabs
+    +-->
+</div>
+</div>
+<div id="main">
+<div id="publishedStrip">
+<!--+
+    |start Subtabs
+    +-->
+<div id="level2tabs"></div>
+<!--+
+    |end Endtabs
+    +-->
+<script type="text/javascript"><!--
+document.write("Last Published: " + document.lastModified);
+//  --></script>
+</div>
+<!--+
+    |breadtrail
+    +-->
+<div class="breadtrail">
+<a href="http://www.apache.org/">apache.org</a> &gt; <a href="http://xml.apache.org/">XML Federation</a> &gt; <a href="http://xmlgraphics.apache.org/">xmlgraphics.apache.org</a><script src="../skin/breadcrumbs.js" language="JavaScript" type="text/javascript"></script>
+</div>
+<!--+
+    |start Menu, mainarea
+    +-->
+<!--+
+    |start Menu
+    +-->
+<div id="menu">
+<div onclick="SwitchMenu('menu_selected_1.1', '../skin/')" id="menu_selected_1.1Title" class="menutitle" style="background-image: url('../skin/images/chapter_open.gif');">FOP Trunk (dev)</div>
+<div id="menu_selected_1.1" class="selectedmenuitemgroup" style="display: block;">
+<div class="menuitem">
+<a href="../trunk/index.html">About</a>
+</div>
+<div class="menuitem">
+<a href="../trunk/upgrading.html">Upgrading</a>
+</div>
+<div onclick="SwitchMenu('menu_selected_1.1.3', '../skin/')" id="menu_selected_1.1.3Title" class="menutitle" style="background-image: url('../skin/images/chapter_open.gif');">Using FOP</div>
+<div id="menu_selected_1.1.3" class="selectedmenuitemgroup" style="display: block;">
+<div class="menuitem">
+<a href="../trunk/compiling.html">Build</a>
+</div>
+<div class="menuitem">
+<a href="../trunk/configuration.html">Configure</a>
+</div>
+<div class="menuitem">
+<a href="../trunk/running.html">Run</a>
+</div>
+<div class="menupage">
+<div class="menupagetitle">Embed</div>
+</div>
+<div class="menuitem">
+<a href="../trunk/servlets.html">Servlets</a>
+</div>
+<div class="menuitem">
+<a href="../trunk/anttask.html">Ant Task</a>
+</div>
+</div>
+<div onclick="SwitchMenu('menu_1.1.4', '../skin/')" id="menu_1.1.4Title" class="menutitle">Features</div>
+<div id="menu_1.1.4" class="menuitemgroup">
+<div class="menuitem">
+<a href="../trunk/output.html">Output Targets</a>
+</div>
+<div class="menuitem">
+<a href="../trunk/intermediate.html">Intermediate Format</a>
+</div>
+<div class="menuitem">
+<a href="../trunk/pdfencryption.html">PDF Encryption</a>
+</div>
+<div class="menuitem">
+<a href="../trunk/pdfa.html">PDF/A</a>
+</div>
+<div class="menuitem">
+<a href="../trunk/pdfx.html">PDF/X</a>
+</div>
+<div class="menuitem">
+<a href="../trunk/graphics.html">Graphics</a>
+</div>
+<div class="menuitem">
+<a href="../trunk/fonts.html">Fonts</a>
+</div>
+<div class="menuitem">
+<a href="../trunk/hyphenation.html">Hyphenation</a>
+</div>
+<div class="menuitem">
+<a href="../trunk/extensions.html">Extensions</a>
+</div>
+<div class="menuitem">
+<a href="../trunk/events.html">Events</a>
+</div>
+<div class="menuitem">
+<a href="../trunk/metadata.html">Metadata</a>
+</div>
+<div class="menuitem">
+<a href="../trunk/accessibility.html">Accessibility</a>
+</div>
+</div>
+</div>
+<div id="credit"></div>
+<div id="roundbottom">
+<img style="display: none" class="corner" height="15" width="15" alt="" src="../skin/images/rc-b-l-15-1body-2menu-3menu.png"></div>
+<!--+
+  |alternative credits
+  +-->
+<div id="credit2">
+<a href="http://us.apachecon.com/"><img border="0" title="ApacheCon US 2009" alt="ApacheCon US 2009 - logo" src="http://apache.org/ads/ApacheCon/2009-usa-125x125.png" style="width: 125px;height: 125px;"></a>
+</div>
+</div>
+<!--+
+    |end Menu
+    +-->
+<!--+
+    |start content
+    +-->
+<div id="content">
+<div title="raw XML" class="xmllink">
+<a class="dida" href="embedding.xml"><img alt="XML - icon" src="../skin/images/xmldoc.gif" class="skin"><br>
+        XML</a>
+</div>
+<div title="Portable Document Format" class="pdflink">
+<a class="dida" href="embedding.pdf"><img alt="PDF -icon" src="../skin/images/pdfdoc.gif" class="skin"><br>
+        PDF</a>
+</div>
+<div class="trail">Font size: 
+	          &nbsp;<input value="Reset" class="resetfont" title="Reset text" onclick="ndeSetTextSize('reset'); return false;" type="button">      
+	          &nbsp;<input value="-a" class="smallerfont" title="Shrink text" onclick="ndeSetTextSize('decr'); return false;" type="button">
+	          &nbsp;<input value="+a" class="biggerfont" title="Enlarge text" onclick="ndeSetTextSize('incr'); return false;" type="button">
+</div>
+<h1>Apache FOP: Embedding</h1>
+<h3>How to Embed FOP in a Java application</h3>
+<div id="front-matter">
+<div id="minitoc-area">
+<ul class="minitoc">
+<li>
+<a href="#overview">Overview</a>
+</li>
+<li>
+<a href="#basics">Basic Usage Pattern</a>
+<ul class="minitoc">
+<li>
+<a href="#basic-logging">Logging</a>
+</li>
+<li>
+<a href="#render">Processing XSL-FO</a>
+</li>
+<li>
+<a href="#render-with-xslt">Processing XSL-FO generated from XML+XSLT</a>
+</li>
+</ul>
+</li>
+<li>
+<a href="#input">Input Sources</a>
+</li>
+<li>
+<a href="#config-internal">Configuring Apache FOP Programmatically</a>
+<ul class="minitoc">
+<li>
+<a href="#fop-factory">Customizing the FopFactory</a>
+</li>
+<li>
+<a href="#user-agent">Customizing the User Agent</a>
+</li>
+</ul>
+</li>
+<li>
+<a href="#config-external">Using a Configuration File</a>
+</li>
+<li>
+<a href="#hints">Hints</a>
+<ul class="minitoc">
+<li>
+<a href="#object-reuse">Object reuse</a>
+</li>
+<li>
+<a href="#awt">AWT issues</a>
+</li>
+<li>
+<a href="#render-info">Getting information on the rendering process</a>
+</li>
+</ul>
+</li>
+<li>
+<a href="#performance">Improving performance</a>
+</li>
+<li>
+<a href="#multithreading">Multithreading FOP</a>
+</li>
+<li>
+<a href="#examples">Examples</a>
+<ul class="minitoc">
+<li>
+<a href="#ExampleFO2PDF">ExampleFO2PDF.java</a>
+</li>
+<li>
+<a href="#ExampleXML2FO">ExampleXML2FO.java</a>
+</li>
+<li>
+<a href="#ExampleXML2PDF">ExampleXML2PDF.java</a>
+</li>
+<li>
+<a href="#ExampleObj2XML">ExampleObj2XML.java</a>
+</li>
+<li>
+<a href="#ExampleObj2PDF">ExampleObj2PDF.java</a>
+</li>
+<li>
+<a href="#ExampleDOM2PDF">ExampleDOM2PDF.java</a>
+</li>
+<li>
+<a href="#ExampleSVG2PDF">ExampleSVG2PDF.java (PDF Transcoder example)</a>
+</li>
+<li>
+<a href="#example-notes">Final notes</a>
+</li>
+</ul>
+</li>
+</ul>
+</div>
+</div>
+  
+<a name="N10015"></a><a name="overview"></a>
+<h2 class="underlined_10">Overview</h2>
+<div class="section">
+<p>
+      Review <a href="running.html">Running FOP</a> for important information that applies
+      to embedded applications as well as command-line use, such as options and performance.
+    </p>
+<p>
+      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.
+    </p>
+<div class="note">
+<div class="label">Note</div>
+<div class="content">
+      We recently changed FOP's outer API to what we consider the final API. This might require
+      some changes in your application. The main reasons for these changes were performance
+      improvements due to better reuse of reusable objects and reduced use of static variables
+      for added flexibility in complex environments.
+    </div>
+</div>
+</div>
+  
+<a name="N10029"></a><a name="basics"></a>
+<h2 class="underlined_10">Basic Usage Pattern</h2>
+<div class="section">
+<p>
+      Apache FOP relies heavily on JAXP. It uses SAX events exclusively to receive the XSL-FO
+      input document. It is therefore a good idea that you know a few things about JAXP (which
+      is a good skill anyway). Let's look at the basic usage pattern for FOP...
+    </p>
+<p>Here is the basic pattern to render an XSL-FO file to PDF:
+    </p>
+<pre class="code">
+import org.apache.fop.apps.FopFactory;
+import org.apache.fop.apps.Fop;
+import org.apache.fop.apps.MimeConstants;
+
+/*..*/
+
+// Step 1: Construct a FopFactory
+// (reuse if you plan to render multiple documents!)
+FopFactory fopFactory = FopFactory.newInstance();
+
+// Step 2: Set up output stream.
+// Note: Using BufferedOutputStream for performance reasons (helpful with FileOutputStreams).
+OutputStream out = new BufferedOutputStream(new FileOutputStream(new File("C:/Temp/myfile.pdf")));
+
+try {
+  // Step 3: Construct fop with desired output format
+  Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, out);
+
+  // Step 4: Setup JAXP using identity transformer
+  TransformerFactory factory = TransformerFactory.newInstance();
+  Transformer transformer = factory.newTransformer(); // identity transformer
+
+  // Step 5: Setup input and output for XSLT transformation
+  // Setup input stream
+  Source src = new StreamSource(new File("C:/Temp/myfile.fo"));
+
+  // Resulting SAX events (the generated FO) must be piped through to FOP
+  Result res = new SAXResult(fop.getDefaultHandler());
+
+  // Step 6: Start XSLT transformation and FOP processing
+  transformer.transform(src, res);
+
+} finally {
+  //Clean-up
+  out.close();
+}</pre>
+<p>
+      Let's discuss these 5 steps in detail:
+    </p>
+<ul>
+      
+<li>
+        
+<strong>Step 1:</strong> You create a new FopFactory instance. The FopFactory instance holds
+        references to configuration information and cached data. It's important to reuse this
+        instance if you plan to render multiple documents during a JVM's lifetime.
+      </li>
+      
+<li>
+        
+<strong>Step 2:</strong> You set up an OutputStream that the generated document
+        will be written to. It's a good idea to buffer the OutputStream as demonstrated
+        to improve performance.
+      </li>
+      
+<li>
+        
+<strong>Step 3:</strong> You create a new Fop instance through one of the factory
+        methods on the FopFactory. You tell the FopFactory what your desired output format
+        is. This is done by using the MIME type of the desired output format (ex. "application/pdf").
+        You can use one of the MimeConstants.* constants. The second parameter is the
+        OutputStream you've setup up in step 2.
+      </li>
+      
+<li>
+        
+<strong>Step 4</strong> We recommend that you use JAXP Transformers even
+        if you don't do XSLT transformations to generate the XSL-FO file. This way
+        you can always use the same basic pattern. The example here sets up an
+        "identity transformer" which just passes the input (Source) unchanged to the
+        output (Result). You don't have to work with a SAXParser if you don't do any
+        XSLT transformations.
+      </li>
+      
+<li>
+        
+<strong>Step 5:</strong> Here you set up the input and output for the XSLT
+        transformation. The Source object is set up to load the "myfile.fo" file.
+        The Result is set up so the output of the XSLT transformation is sent to FOP.
+        The FO file is sent to FOP in the form of SAX events which is the most efficient
+        way. Please always avoid saving intermediate results to a file or a memory buffer
+        because that affects performance negatively.
+      </li>
+      
+<li>
+        
+<strong>Step 6:</strong> Finally, we start the XSLT transformation by starting
+        the JAXP Transformer. As soon as the JAXP Transformer starts to send its output
+        to FOP, FOP itself starts its processing in the background. When the
+        <span class="codefrag">transform()</span> method returns FOP will also have finished converting
+        the FO file to a PDF file and you can close the OutputStream.
+        <div class="note">
+<div class="label">Tip!</div>
+<div class="content">
+          It's a good idea to enclose the whole conversion in a try..finally statement. If
+          you close the OutputStream in the finally section, this will make sure that the
+          OutputStream is properly closed even if an exception occurs during the conversion.
+        </div>
+</div>
+      
+</li>
+    
+</ul>
+<p>
+      If you're not totally familiar with JAXP Transformers, please have a look at the
+      <a href="#examples">Embedding examples</a> below. The section contains examples
+      for all sorts of use cases. If you look at all of them in turn you should be able
+      to see the patterns in use and the flexibility this approach offers without adding
+      too much complexity.
+    </p>
+<p>
+      This may look complicated at first, but it's really just the combination of an
+      XSL transformation and a FOP run. It's also easy to comment out the FOP part
+      for debugging purposes, for example when you're tracking down a bug in your
+      stylesheet. You can easily write the XSL-FO output from the XSL transformation
+      to a file to check if that part generates the expected output. An example for that
+      can be found in the <a href="#examples">Embedding examples</a> (See "ExampleXML2FO").
+    </p>
+<a name="N10078"></a><a name="basic-logging"></a>
+<h3 class="underlined_5">Logging</h3>
+<p>
+        Logging is now a little different than it was in FOP 0.20.5. We've switched from
+        Avalon Logging to <a class="external" href="http://commons.apache.org/logging/">Jakarta Commons Logging</a>.
+        While with Avalon Logging the loggers were directly given to FOP, FOP now retrieves
+        its logger(s) through a statically available LogFactory. This is similar to the
+        general pattern that you use when you work with Apache Log4J directly, for example.
+        We call this "static logging" (Commons Logging, Log4J) as opposed to "instance logging"
+        (Avalon Logging). This has a consequence: You can't give FOP a logger for each
+        processing run anymore. The log output of multiple, simultaneously running FOP instances
+        is sent to the same logger.
+      </p>
+<p>
+        By default, <a class="external" href="http://commons.apache.org/logging/">Jakarta Commons Logging</a> uses
+        JDK logging (available in JDKs 1.4 or higher) as its backend. You can configure Commons
+        Logging to use an alternative backend, for example Log4J. Please consult the
+        <a class="external" href="http://commons.apache.org/logging/">documentation for Jakarta Commons Logging</a> on
+        how to configure alternative backends.
+      </p>
+<p>
+        As a result of the above we differentiate between two kinds of "logging":
+      </p>
+<ul>
+        
+<li>(FOP-)Developer-oriented logging</li>
+        
+<li>
+<a href="events.html">User/Integrator-oriented feedback</a> (NEW!)</li>
+      
+</ul>
+<p>
+        The use of "feedback" instead of "logging" is intentional. Most people were using
+        log output as a means to get feedback from events within FOP. Therefore, FOP now
+        includes an <span class="codefrag">event</span> package which can be used to receive feedback from
+        the layout engine and other components within FOP <strong>per rendering run</strong>.
+        This feedback is not just some
+        text but event objects with parameters so these events can be interpreted by code.
+        Of course, there is a facility to turn these events into normal human-readable
+        messages. For details, please read on on the <a href="events.html">Events page</a>.
+        This leaves normal logging to be mostly a thing used by the FOP developers
+        although anyone can surely activate certain logging categories but the feedback
+        from the loggers won't be separated by processing runs. If this is required,
+        the <a href="events.html">Events subsystem</a> is the right approach.
+      </p>
+<a name="N100B1"></a><a name="render"></a>
+<h3 class="underlined_5">Processing XSL-FO</h3>
+<p>
+        Once the Fop instance is set up, call <span class="codefrag">getDefaultHandler()</span> 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
+        <span class="codefrag">startDocument()</span> method is called. Processing stops again when the
+        DefaultHandler's <span class="codefrag">endDocument()</span> method is called. Please refer to the basic
+        usage pattern shown above to render a simple XSL-FO document.
+      </p>
+<a name="N100C4"></a><a name="render-with-xslt"></a>
+<h3 class="underlined_5">Processing XSL-FO generated from XML+XSLT</h3>
+<p>
+        If you want to process XSL-FO generated from XML using XSLT we recommend
+        again using standard JAXP to do the XSLT part and piping the generated SAX
+        events directly through to FOP. The only thing you'd change to do that
+        on the basic usage pattern above is to set up the Transformer differently:
+      </p>
+<pre class="code">
+  //without XSLT:
+  //Transformer transformer = factory.newTransformer(); // identity transformer
+
+  //with XSLT:
+  Source xslt = new StreamSource(new File("mystylesheet.xsl"));
+  Transformer transformer = factory.newTransformer(xslt);</pre>
+</div>
+  
+<a name="N100D3"></a><a name="input"></a>
+<h2 class="underlined_10">Input Sources</h2>
+<div class="section">
+<p>
+      The input XSL-FO document is always received by FOP as a SAX stream (see the
+      <a href="../dev/design/parsing.html">Parsing Design Document</a> for the rationale).
+    </p>
+<p>
+      However, you may not always have your input document available as a SAX stream.
+      But with JAXP it's easy to convert different input sources to a SAX stream so you
+      can pipe it into FOP. That sounds more difficult than it is. You simply have
+      to set up the right Source instance as input for the JAXP transformation.
+      A few examples:
+    </p>
+<ul>
+      
+<li>
+        
+<strong>URL:</strong> <span class="codefrag">Source src = new StreamSource("http://localhost:8080/testfile.xml");</span>
+      
+</li>
+      
+<li>
+        
+<strong>File:</strong> <span class="codefrag">Source src = new StreamSource(new File("C:/Temp/myinputfile.xml"));</span>
+      
+</li>
+      
+<li>
+        
+<strong>String:</strong> <span class="codefrag">Source src = new StreamSource(new StringReader(myString)); // myString is a String</span>
+      
+</li>
+      
+<li>
+        
+<strong>InputStream:</strong> <span class="codefrag">Source src = new StreamSource(new MyInputStream(something));</span>
+      
+</li>
+      
+<li>
+        
+<strong>Byte Array:</strong> <span class="codefrag">Source src = new StreamSource(new ByteArrayInputStream(myBuffer)); // myBuffer is a byte[] here</span>
+      
+</li>
+      
+<li>
+        
+<strong>DOM:</strong> <span class="codefrag">Source src = new DOMSource(myDocument); // myDocument is a Document or a Node</span>
+      
+</li>
+      
+<li>
+        
+<strong>Java Objects:</strong> Please have a look at the <a href="#examples">Embedding examples</a> which contain an example for this.
+      </li>
+    
+</ul>
+<p>
+      There are a variety of upstream data manipulations possible.
+      For example, you may have a DOM and an XSL stylesheet; or you may want to
+      set variables in the stylesheet. Interface documentation and some cookbook
+      solutions to these situations are provided in
+      <a class="external" href="http://xml.apache.org/xalan-j/usagepatterns.html">Xalan Basic Usage Patterns</a>.
+    </p>
+</div>
+  
+<a name="N1012E"></a><a name="config-internal"></a>
+<h2 class="underlined_10">Configuring Apache FOP Programmatically</h2>
+<div class="section">
+<p>
+      Apache FOP provides two levels on which you can customize FOP's
+      behaviour: the FopFactory and the user agent.
+    </p>
+<a name="N10137"></a><a name="fop-factory"></a>
+<h3 class="underlined_5">Customizing the FopFactory</h3>
+<p>
+        The FopFactory holds configuration data and references to objects which are reusable over
+        multiple rendering runs. It's important to instantiate it only once (except in special
+        environments) and reuse it every time to create new FOUserAgent and Fop instances.
+      </p>
+<p>
+        You can set all sorts of things on the FopFactory:
+      </p>
+<ul>
+        
+<li>
+          
+<p>
+            The <strong>font base URL</strong> to use when resolving relative URLs for fonts. Example:
+          </p>
+          
+<pre class="code">fopFactory.getFontManager().setFontBaseURL("file:///C:/Temp/fonts");</pre>
+        
+</li>
+        
+<li>
+          
+<p>
+            The <strong>hyphenation base URL</strong> to use when resolving relative URLs for
+            hyphenation patterns. Example:
+          </p>
+          
+<pre class="code">fopFactory.setHyphenBaseURL("file:///C:/Temp/hyph");</pre>
+        
+</li>
+        
+<li>
+          
+<p>
+            Disable <strong>strict validation</strong>. When disabled FOP is less strict about the rules
+            established by the XSL-FO specification. Example:
+          </p>
+          
+<pre class="code">fopFactory.setStrictValidation(false);</pre>
+        
+</li>
+        
+<li>
+          
+<p>
+            Enable an <strong>alternative set of rules for text indents</strong> that tries to mimic the behaviour of many commercial
+            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:
+          </p>
+          
+<pre class="code">fopFactory.setBreakIndentInheritanceOnReferenceAreaBoundary(true);</pre>
+        
+</li>
+        
+<li>
+          
+<p>
+            Set the <strong>source resolution</strong> 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:
+          </p>
+          
+<pre class="code">fopFactory.setSourceResolution(96); // =96dpi (dots/pixels per Inch)</pre>
+        
+</li>
+        
+<li>
+          
+<p>
+            Manually add an <strong>ElementMapping instance</strong>. 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). Example:
+          </p>
+          
+<pre class="code">fopFactory.addElementMapping(myElementMapping); // myElementMapping is a org.apache.fop.fo.ElementMapping</pre>
+        
+</li>
+        
+<li>
+          
+<p>
+            Set a <strong>URIResolver</strong> for custom URI resolution. By supplying a JAXP URIResolver you can add
+            custom URI resolution functionality to FOP. For example, you can use
+            <a class="external" href="http://xml.apache.org/commons/components/resolver/">Apache XML Commons Resolver</a> to make use of XCatalogs. Example:
+          </p>
+          
+<pre class="code">fopFactory.setURIResolver(myResolver); // myResolver is a javax.xml.transform.URIResolver</pre>
+          
+<div class="note">
+<div class="label">Note</div>
+<div class="content">
+            Both the FopFactory and the FOUserAgent have a method to set a URIResolver. The URIResolver on the FopFactory
+            is primarily used to resolve URIs on factory-level (hyphenation patterns, for example) and it is always used
+            if no other URIResolver (for example on the FOUserAgent) resolved the URI first.
+          </div>
+</div>
+        
+</li>
+      
+</ul>
+<a name="N101A9"></a><a name="user-agent"></a>
+<h3 class="underlined_5">Customizing the User Agent</h3>
+<p>
+        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 appropriate factory method on FopFactory and pass that
+        to the factory method that will create a new Fop instance:
+      </p>
+<pre class="code">
+  FopFactory fopFactory = FopFactory.newInstance(); // Reuse the FopFactory if possible!
+  // do the following for each new rendering run
+  FOUserAgent userAgent = fopFactory.newFOUserAgent();
+  // customize userAgent
+  Fop fop = fopFactory.newFop(MimeConstants.MIME_POSTSCRIPT, userAgent, out);</pre>
+<p>
+        You can do all sorts of things on the user agent:
+      </p>
+<ul>
+        
+<li>
+          
+<p>
+            The <strong>base URL</strong> to use when resolving relative URLs. Example:
+          </p>
+          
+<pre class="code">userAgent.setBaseURL("file:///C:/Temp/");</pre>
+        
+</li>
+        
+<li>
+          
+<p>
+            Set the <strong>producer</strong> of the document. This is metadata information that can be used for certain output formats such as PDF. The default producer is "Apache FOP". Example:
+          </p>
+          
+<pre class="code">userAgent.setProducer("MyKillerApplication");</pre>
+        
+</li>
+        
+<li>
+          
+<p>
+            Set the <strong>creating user</strong> of the document. This is metadata information that can be used for certain output formats such as PDF. Example:
+          </p>
+          
+<pre class="code">userAgent.setCreator("John Doe");</pre>
+        
+</li>
+        
+<li>
+          
+<p>
+            Set the <strong>author</strong> of the document. This is metadata information that can be used for certain output formats such as PDF. Example:
+          </p>
+          
+<pre class="code">userAgent.setAuthor("John Doe");</pre>
+        
+</li>
+        
+<li>
+          
+<p>
+            Override the <strong>creation date and time</strong> of the document. This is metadata information that can be used for certain output formats such as PDF. Example:
+          </p>
+          
+<pre class="code">userAgent.setCreationDate(new Date());</pre>
+        
+</li>
+        
+<li>
+          
+<p>
+            Set the <strong>title</strong> of the document. This is metadata information that can be used for certain output formats such as PDF. Example:
+          </p>
+          
+<pre class="code">userAgent.setTitle("Invoice No 138716847");</pre>
+        
+</li>
+        
+<li>
+          
+<p>
+            Set the <strong>keywords</strong> of the document. This is metadata information that can be used for certain output formats such as PDF. Example:
+          </p>
+          
+<pre class="code">userAgent.setKeywords("XML XSL-FO");</pre>
+        
+</li>
+        
+<li>
+          
+<p>
+            Set the <strong>target resolution</strong> for the document. This is used to
+            specify the output resolution for bitmap images generated by bitmap renderers
+            (such as the TIFF renderer) and by bitmaps generated by Apache Batik for filter
+            effects and such. Default: 72 dpi. Example:
+          </p>
+          
+<pre class="code">userAgent.setTargetResolution(300); // =300dpi (dots/pixels per Inch)</pre>
+        
+</li>
+        
+<li>
+          
+<p>
+            Set <strong>your own Renderer instance</strong>. If you want to supply your own renderer or
+            configure a Renderer in a special way you can give the instance to the FOUserAgent. Normally,
+            the Renderer instance is created by FOP. Example:
+          </p>
+          
+<pre class="code">userAgent.setRendererOverride(myRenderer); // myRenderer is an org.apache.fop.render.Renderer</pre>
+        
+</li>
+        
+<li>
+          
+<p>
+            Set <strong>your own FOEventHandler instance</strong>. If you want to supply your own FOEventHandler or
+            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:
+          </p>
+          
+<pre class="code">userAgent.setFOEventHandlerOverride(myFOEventHandler); // myFOEventHandler is an org.apache.fop.fo.FOEventHandler</pre>
+        
+</li>
+        
+<li>
+          
+<p>
+            Set a <strong>URIResolver</strong> for custom URI resolution. By supplying a JAXP URIResolver you can add
+            custom URI resolution functionality to FOP. For example, you can use
+            <a class="external" href="http://xml.apache.org/commons/components/resolver/">Apache XML Commons Resolver</a> to make use of XCatalogs. Example:
+          </p>
+          
+<pre class="code">userAgent.setURIResolver(myResolver); // myResolver is a javax.xml.transform.URIResolver</pre>
+          
+<div class="note">
+<div class="label">Note</div>
+<div class="content">
+            Both the FopFactory and the FOUserAgent have a method to set a URIResolver. The URIResolver on the FOUserAgent is
+            used for resolving URIs which are document-related. If it's not set or cannot resolve a URI, the URIResolver
+            from the FopFactory is used.
+          </div>
+</div>
+        
+</li>
+      
+</ul>
+<div class="note">
+<div class="label">Note</div>
+<div class="content">
+        You should not reuse an FOUserAgent instance between FOP rendering runs although you can. Especially
+        in multi-threaded environment, this is a bad idea.
+      </div>
+</div>
+</div>
+  
+<a name="N10257"></a><a name="config-external"></a>
+<h2 class="underlined_10">Using a Configuration File</h2>
+<div class="section">
+<p>
+      Instead of setting the parameters manually in code as shown above you can also set
+      many values from an XML configuration file:
+    </p>
+<pre class="code">
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
+
+/*..*/
+
+DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder();
+Configuration cfg = cfgBuilder.buildFromFile(new File("C:/Temp/mycfg.xml"));
+fopFactory.setUserConfig(cfg);
+
+/* ..or.. */
+
+fopFactory.setUserConfig(new File("C:/Temp/mycfg.xml"));</pre>
+<p>
+      The layout of the configuration file is described on the <a href="configuration.html">Configuration page</a>.
+    </p>
+</div>
+  
+<a name="N1026C"></a><a name="hints"></a>
+<h2 class="underlined_10">Hints</h2>
+<div class="section">
+<a name="N10272"></a><a name="object-reuse"></a>
+<h3 class="underlined_5">Object reuse</h3>
+<p>
+        Fop instances shouldn't (and can't) be reused. Please recreate
+        Fop and FOUserAgent instances for each rendering run using the FopFactory.
+        This is a cheap operation as all reusable information is held in the
+        FopFactory. That's why it's so important to reuse the FopFactory instance.
+     </p>
+<a name="N1027C"></a><a name="awt"></a>
+<h3 class="underlined_5">AWT issues</h3>
+<p>
+        If your XSL-FO files contain SVG then Apache Batik will be used. When Batik is
+        initialised it uses certain classes in <span class="codefrag">java.awt</span> that
+        intialise the Java AWT classes. This means that a daemon thread
+        is created by the JVM and on Unix it will need to connect to a
+        DISPLAY.
+      </p>
+<p>
+        The thread means that the Java application may not automatically quit
+        when finished, you will need to call <span class="codefrag">System.exit()</span>. These
+        issues should be fixed in the JDK 1.4.
+      </p>
+<p>
+        If you run into trouble running FOP on a head-less server, please see the
+        <a href="graphics.html#batik">notes on Batik</a>.
+      </p>
+<a name="N10296"></a><a name="render-info"></a>
+<h3 class="underlined_5">Getting information on the rendering process</h3>
+<p>
+        To get the number of pages that were rendered by FOP you can call
+        <span class="codefrag">Fop.getResults()</span>. This returns a <span class="codefrag">FormattingResults</span> object
+        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
+        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.
+      </p>
+</div>
+  
+<a name="N102A7"></a><a name="performance"></a>
+<h2 class="underlined_10">Improving performance</h2>
+<div class="section">
+<p>
+      There are several options to consider:
+    </p>
+<ul>
+      
+<li>
+        Whenever possible, try to use SAX to couple the individual components involved
+        (parser, XSL transformer, SQL datasource etc.).
+      </li>
+      
+<li>
+        Depending on the target OutputStream (in case of a FileOutputStream, but not
+        for a ByteArrayOutputStream, for example) it may improve performance considerably
+        if you buffer the OutputStream using a BufferedOutputStream:
+        <span class="codefrag">out = new java.io.BufferedOutputStream(out);</span>
+        
+<br>
+        Make sure you properly close the OutputStream when FOP is finished.
+      </li>
+      
+<li>
+        Cache the stylesheet. If you use the same stylesheet multiple times
+        you can set up a JAXP <span class="codefrag">Templates</span> object and reuse it each time you do
+        the XSL transformation.  (More information can be found
+        <a class="external" href="http://www.javaworld.com/javaworld/jw-05-2003/jw-0502-xsl.html">here</a>.)
+      </li>
+      
+<li>
+        Use an XSLT compiler like <a class="external" href="http://xml.apache.org/xalan-j/xsltc_usage.html">XSLTC</a>
+        that comes with Xalan-J.
+      </li>
+      
+<li>
+        Fine-tune your stylesheet to make the XSLT process more efficient and to create XSL-FO that can
+        be processed by FOP more efficiently. Less is more: Try to make use of property inheritance where possible.
+      </li>
+      
+<li>
+        You may also wish to consider trying to reduce <a href="http://xmlgraphics.apache.org/fop/trunk/running.html#memory">memory usage</a>.
+      </li>
+    
+</ul>
+</div>
+  
+<a name="N102DC"></a><a name="multithreading"></a>
+<h2 class="underlined_10">Multithreading FOP</h2>
+<div class="section">
+<p>
+      Apache FOP may currently not be completely thread safe.
+      The code has not been fully tested for multi-threading issues, yet.
+      If you encounter any suspicious behaviour, please notify us.
+    </p>
+<p>
+      There is also a known issue with fonts being jumbled between threads when using
+      the Java2D/AWT renderer (which is used by the -awt and -print output options).
+      In general, you cannot safely run multiple threads through the AWT renderer.
+    </p>
+</div>
+
+<a name="N102E9"></a><a name="examples"></a>
+<h2 class="underlined_10">Examples</h2>
+<div class="section">
+<p>
+   The directory "{fop-dir}/examples/embedding" contains several working examples.
+  </p>
+<a name="N102F2"></a><a name="ExampleFO2PDF"></a>
+<h3 class="underlined_5">ExampleFO2PDF.java</h3>
+<p>This
+        <a class="external" href="http://svn.apache.org/viewcvs.cgi/xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleFO2PDF.java?view=markup">
+            example</a>
+demonstrates the basic usage pattern to transform an XSL-FO
+file to PDF using FOP.
+    </p>
+<div id="" style="text-align: center;">
+<img id="" class="figure" alt="Example XSL-FO to PDF" src="images/EmbeddingExampleFO2PDF.png"></div>
+<a name="N10304"></a><a name="ExampleXML2FO"></a>
+<h3 class="underlined_5">ExampleXML2FO.java</h3>
+<p>This
+        <a class="external" href="http://svn.apache.org/viewcvs.cgi/xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleXML2FO.java?view=markup">
+            example</a>
+has nothing to do with FOP. It is there to show you how an XML
+file can be converted to XSL-FO using XSLT. The JAXP API is used to do the
+transformation. Make sure you've got a JAXP-compliant XSLT processor in your
+classpath (ex. <a class="external" href="http://xml.apache.org/xalan-j">Xalan</a>).
+    </p>
+<div id="" style="text-align: center;">
+<img id="" class="figure" alt="Example XML to XSL-FO" src="images/EmbeddingExampleXML2FO.png"></div>
+<a name="N1031A"></a><a name="ExampleXML2PDF"></a>
+<h3 class="underlined_5">ExampleXML2PDF.java</h3>
+<p>This
+        <a class="external" href="http://svn.apache.org/viewcvs.cgi/xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleXML2PDF.java?view=markup">
+        example</a>
+demonstrates how you can convert an arbitrary XML file to PDF
+using XSLT and XSL-FO/FOP. It is a combination of the first two examples
+above. The example uses JAXP to transform the XML file to XSL-FO and FOP to
+transform the XSL-FO to PDF.
+    </p>
+<div id="" style="text-align: center;">
+<img id="" class="figure" alt="Example XML to PDF (via XSL-FO)" src="images/EmbeddingExampleXML2PDF.png"></div>
+<p>
+The output (XSL-FO) from the XSL transformation is piped through to FOP using
+SAX events. This is the most efficient way to do this because the
+intermediate result doesn't have to be saved somewhere. Often, novice users
+save the intermediate result in a file, a byte array or a DOM tree. We
+strongly discourage you to do this if it isn't absolutely necessary. The
+performance is significantly higher with SAX.
+    </p>
+<a name="N1032F"></a><a name="ExampleObj2XML"></a>
+<h3 class="underlined_5">ExampleObj2XML.java</h3>
+<p>This
+    <a class="external" href="http://svn.apache.org/viewcvs.cgi/xmlgraphics/fop/trunk/examples/embedding/java/embedding/ExampleObj2XML.java?view=markup">
+        example</a>
+is a preparatory example for the next one. It's an example that
+shows how an arbitrary Java object can be converted to XML. It's an often
+needed task to do this. Often people create a DOM tree from a Java object and
+use that. This is pretty straightforward. The example here, however, shows how
+to do this using SAX, which will probably be faster and not even more
+complicated once you know how this works.
+    </p>
+<div id="" style="text-align: center;">
+<img id="" class="figure" alt="Example Java object to XML" src="images/EmbeddingExampleObj2XML.png"></div>
+<p>
+For this example we've created two classes: ProjectTeam and ProjectMember
+(found in xml-fop/examples/embedding/java/embedding/model). They represent
+the same data structure found in
+xml-fop/examples/embedding/xml/xml/projectteam.xml. We want to serialize to XML a
+project team with several members which exist as Java objects.
+Therefore we created the two classes: ProjectTeamInputSource and
+ProjectTeamXMLReader (in the same place as ProjectTeam above).
+    </p>
+<p>
+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.
+    </p>
+<p>
+Have a look at the source of ExampleObj2XML.java to find out how this is

[... 71 lines stripped ...]


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: commits-help@xmlgraphics.apache.org