Return-Path: X-Original-To: apmail-xmlgraphics-commits-archive@www.apache.org Delivered-To: apmail-xmlgraphics-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D4BB9E3A6 for ; Tue, 4 Dec 2012 16:00:50 +0000 (UTC) Received: (qmail 63088 invoked by uid 500); 4 Dec 2012 16:00:50 -0000 Mailing-List: contact commits-help@xmlgraphics.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: general@xmlgraphics.apache.org Delivered-To: mailing list commits@xmlgraphics.apache.org Received: (qmail 63081 invoked by uid 99); 4 Dec 2012 16:00:50 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 04 Dec 2012 16:00:50 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 04 Dec 2012 16:00:46 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 55AEE2388C70 for ; Tue, 4 Dec 2012 16:00:03 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r840735 [7/19] - in /websites/staging/xmlgraphics/trunk/content: ./ batik/ batik/dev/ batik/tools/ batik/using/ batik/using/scripting/ commons/ fop/ fop/0.95/ fop/1.0/ fop/1.1/ fop/trunk/ Date: Tue, 04 Dec 2012 15:59:44 -0000 To: commits@xmlgraphics.apache.org From: buildbot@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20121204160003.55AEE2388C70@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Modified: websites/staging/xmlgraphics/trunk/content/commons/postscript.html ============================================================================== --- websites/staging/xmlgraphics/trunk/content/commons/postscript.html (original) +++ websites/staging/xmlgraphics/trunk/content/commons/postscript.html Tue Dec 4 15:59:34 2012 @@ -136,7 +136,7 @@ $(document).ready(function () {

Tools for Adobe PostScript

-

Overview

+

Overview

Apache™ XML Graphics Commons contains various tools for writing and processing Adobe PostScript files. This includes:

  • @@ -150,24 +150,32 @@ $(document).ready(function () { We don't currently include a PostScript interpreter though we would love to have one. A Java-based PostScript interpreter to keep an eye on is the one from the FOray project .

-

The PostScript generator

+

The PostScript generator

The "PSGenerator" class can help writing PostScript files. It deals with things like escaping, saving/tracking/restoring graphics state, writing DSC comments and tracking of DSC resources.

You will rarely interact with the PS generator itself, as it is probably more interesting to generate a PostScript file using Java2D which is described in the following section.

-

Java2D: Graphics2D implementation for generating PostScript and EPS

+

Java2D: Graphics2D implementation for generating PostScript and EPS

We provide two classes (PSDocumentGraphics2D and EPSDocumentGraphics2D) which you can use to generated complete PostScript files using normal Java2D means. The difference between the two classes is that the EPS variant creates a fully compliant Encapsulated PostScript file while the PS variant simply creates a normal DSC-compliant level 2 PostScript file. It depends on your requirement which variant you choose. The PS variant is mostly for printing purposes while the EPS variant is better suited for inclusion in other documents.

-

Creating an EPS file

+

Creating an EPS file

Creating an EPS file using the Graphics2D implementation is easy. Instantiate EPSDocumentGraphics2D, set a GraphicContext and set up the output document. Here's an example:

-

import org.apache.xmlgraphics.java2d.ps.EPSDocumentGraphics2D;

-

-

EPSDocumentGraphics2D g2d = new EPSDocumentGraphics2D(false); -g2d.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext());

-

//Set up the document size -g2d.setupDocument(out, 400, 200); //400pt x 200pt -//out is the OutputStream to write the EPS to

-

g2d.drawRect(10, 10, 50, 50); //paint a rectangle using normal Java2D calls

-

g2d.finish(); //Wrap up and finalize the EPS file

+
import org.apache.xmlgraphics.java2d.ps.EPSDocumentGraphics2D;
+
+[..]
+
+EPSDocumentGraphics2D g2d = new EPSDocumentGraphics2D(false);
+g2d.setGraphicContext(new org.apache.xmlgraphics.java2d.GraphicContext());
+
+//Set up the document size
+g2d.setupDocument(out, 400, 200); //400pt x 200pt
+//out is the OutputStream to write the EPS to
+
+g2d.drawRect(10, 10, 50, 50); //paint a rectangle using normal Java2D calls
+
+g2d.finish(); //Wrap up and finalize the EPS file
+
+ +

A complete example for generating an EPS files can be found in the "examples" directory in the distribution.

-

DSC parser/processor

+

DSC parser/processor

Many PostScript files use special comments to structure a document. This allows manipulation of PostScript files without interpreting them. These special comments are defined in the Document Structuring Conventions . The code in Commons is designed to work with DSC 3.0. For details on how DSC is used, please take a look at the DSC specification.

The DSC support in Commons was primarily developed to implement resource optimization features in Apache FOP 's PostScript output support. Resources like images which are used repeatedly in a document should not be written to the PostScript file each time it is used. Instead it is written once at the beginning of the file as a PostScript form. The form is then called whenever the image needs painting.

But the DSC parser could potentially be used for other purposes. The most obvious is extracting a subset of pages from a DSC-compliant file. Assume you want to print only page 45 to 57 of a particular document. There's an example that demonstrates exactly this. Check out the "examples" directory in the distribution. Other potential use cases for the DSC parser are:

Modified: websites/staging/xmlgraphics/trunk/content/fop/0.95/anttask.html ============================================================================== --- websites/staging/xmlgraphics/trunk/content/fop/0.95/anttask.html (original) +++ websites/staging/xmlgraphics/trunk/content/fop/0.95/anttask.html Tue Dec 4 15:59:34 2012 @@ -346,16 +346,16 @@ $(document).ready(function () {

Description

The FOP Ant task will convert XSL-FO documents to PDF, PS, PCL etc. output (see Output formats for available formats).

To call FOP tasks within Ant, first add a FOP task definition to your Ant build file. One method of defining the task is as follows:

-
<property name="fop.home" value="....path to your FOP HOME directory..."/>
+
<property name="fop.home" value="....path to your FOP HOME directory..."/>
 
-<taskdef name="fop" 
+<taskdef name="fop"
          classname="org.apache.fop.tools.anttasks.Fop">
   <classpath>
-    <fileset dir="${fop.home}/lib">
-      <include name="*.jar"/>
+    <fileset dir="${fop.home}/lib">
+      <include name="*.jar"/>
     </fileset>
-    <fileset dir="${fop.home}/build">
-      <include name="fop.jar"/>
+    <fileset dir="${fop.home}/build">
+      <include name="fop.jar"/>
       <include name="fop-hyph.jar" />
     </fileset>
   </classpath>
@@ -451,7 +451,7 @@ $(document).ready(function () {
 

Examples

The following example converts a single XSL-FO file to a PDF document:

<target name="generate-pdf" description="Generates a single PDF file">
-   <fop format="application/pdf" 
+   <fop format="application/pdf"
         fofile="c:\working\foDirectory\foDocument.fo"
         outfile="c:\working\pdfDirectory\pdfDocument.pdf" />
 </target>
@@ -459,12 +459,12 @@ $(document).ready(function () {
 
 
 

This example converts all XSL-FO files within an entire directory to PostScript:

-
<target name="generate-multiple-ps" 
+
<target name="generate-multiple-ps"
         description="Generates multiple PostScript files">
-   <fop format="application/postscript" 
-        outdir="${build.dir}" messagelevel="debug">
-        <fileset dir="${fo.examples.dir}">
-           <include name="*.fo"/>
+   <fop format="application/postscript"
+        outdir="${build.dir}" messagelevel="debug">
+        <fileset dir="${fo.examples.dir}">
+           <include name="*.fo"/>
         </fileset>
    </fop>
 </target>

Modified: websites/staging/xmlgraphics/trunk/content/fop/0.95/configuration.html
==============================================================================
--- websites/staging/xmlgraphics/trunk/content/fop/0.95/configuration.html (original)
+++ websites/staging/xmlgraphics/trunk/content/fop/0.95/configuration.html Tue Dec  4 15:59:34 2012
@@ -473,84 +473,84 @@ $(document).ready(function () {
 

Renderer configuration

Each Renderer has its own configuration section which is identified by the MIME type the Renderer is written for, ex. "application/pdf" for the PDF Renderer.

The configuration for the PDF Renderer could look like this:

-
  <renderers>
-    <renderer mime="application/pdf">
-      <filterList>
-        <!-- provides compression using zlib flate (default is on) -->
-        <value>flate</value>
-      </filterList>
-      <fonts>
-        <font metrics-url="arial.xml" kerning="yes" embed-url="arial.ttf">
-          <font-triplet name="Arial" style="normal" weight="normal"/>
-          <font-triplet name="ArialMT" style="normal" weight="normal"/>
-        </font>
-        <font metrics-url="arialb.xml" kerning="yes" embed-url="arialb.ttf">
-          <font-triplet name="Arial" style="normal" weight="bold"/>
-          <font-triplet name="ArialMT" style="normal" weight="bold"/>
-        </font>
-      </fonts>
-    </renderer>
+
<renderers>
+  <renderer mime="application/pdf">
+    <filterList>
+      <!-- provides compression using zlib flate (default is on) -->
+      <value>flate</value>
+    </filterList>
+    <fonts>
+      <font metrics-url="arial.xml" kerning="yes" embed-url="arial.ttf">
+        <font-triplet name="Arial" style="normal" weight="normal"/>
+        <font-triplet name="ArialMT" style="normal" weight="normal"/>
+      </font>
+      <font metrics-url="arialb.xml" kerning="yes" embed-url="arialb.ttf">
+        <font-triplet name="Arial" style="normal" weight="bold"/>
+        <font-triplet name="ArialMT" style="normal" weight="bold"/>
+      </font>
+    </fonts>
+  </renderer>
 
-    <renderer mime="application/postscript">
-    <!-- etc. etc..... -->
+  <renderer mime="application/postscript">
+  <!-- etc. etc..... -->
 

The details on the font configuration can be found on the separate Fonts page. Note especially the section entitled Register Fonts with FOP .

Special Settings for the PDF Renderer

The configuration element for the PDF renderer contains two elements. One is for the font configuration (please follow the link above) and one is for the "filter list". The filter list controls how the individual objects in a PDF file are encoded. By default, all objects get "flate" encoded (i.e. simply compressed with the same algorithm that is also used in ZIP files). Most users don't need to change that setting. For debugging purposes, it may be desired not to compress the internal objects at all so the generated PDF commands can be read. In that case, you can simply use the following filter list. The second filter list (type="image") ensures that all images still get compressed but also ASCII-85 encoded so the produced PDF file is still easily readable in a text editor.

-
    <renderer mime="application/pdf">
-      <filterList>
-        <value>null</value>
-      </filterList>
-      <filterList type="image">
-        <value>flate</value>
-        <value>ascii-85</value>
-      </filterList>
+
<renderer mime="application/pdf">
+  <filterList>
+    <value>null</value>
+  </filterList>
+  <filterList type="image">
+    <value>flate</value>
+    <value>ascii-85</value>
+  </filterList>
 
-      <fonts....
-    </renderer>
+  <fonts....
+</renderer>
 

Another (optional) setting specific to the PDF Renderer is an output color profile, an ICC color profile which indicates the target color space the PDF file is generated for. This setting is mainly used in conjunction with the PDF/X feature. An example:

-
    <renderer mime="application/pdf">
-      <filterList...
+
<renderer mime="application/pdf">
+  <filterList...
 
-      <output-profile>C:\FOP\Color\EuropeISOCoatedFOGRA27.icc</output-profile>
+  <output-profile>C:\FOP\Color\EuropeISOCoatedFOGRA27.icc</output-profile>
 
-      <fonts....
-      </renderer>
+  <fonts....
+  </renderer>
 

Some people don't have high requirements on color fidelity but instead want the smallest PDF file sizes possible. In this case it's possible to disable the default sRGB color space which XSL-FO requires. This will cause RGB colors to be generated as device-specific RGB. Please note that this option is unavailable (and will cause an error) if you enable PDF/A or PDF/X functionality or if you specify an output profile. This setting will make the PDF about 4KB smaller. To disable the sRGB color space add the following setting:

-
    <renderer mime="application/pdf">
-      <filterList...
+
<renderer mime="application/pdf">
+  <filterList...
 
-      <disable-srgb-colorspace>true</disable-srgb-colorspace>
+  <disable-srgb-colorspace>true</disable-srgb-colorspace>
 
-      <fonts....
-      </renderer>
+  <fonts....
+  </renderer>
 

Special Settings for the PostScript Renderer

Besides the normal font configuration (the same "fonts" element as for the PDF renderer) the PostScript renderer has an additional setting to force landscape pages to be rotated to fit on a page inserted into the printer in portrait mode. Set the value to "true" to activate this feature. The default is "false". Example:

-
    <renderer mime="application/postscript">
-      <auto-rotate-landscape>true</auto-rotate-landscape>
+
<renderer mime="application/postscript">
+  <auto-rotate-landscape>true</auto-rotate-landscape>
 
-      <fonts>
-        <font metrics-url="arial.xml" kerning="yes" embed-url="arial.ttf">
-          <font-triplet name="Arial" style="normal" weight="normal"/>
-          <font-triplet name="ArialMT" style="normal" weight="normal"/>
-        </font>
-        <font metrics-url="arialb.xml" kerning="yes" embed-url="arialb.ttf">
-          <font-triplet name="Arial" style="normal" weight="bold"/>
-          <font-triplet name="ArialMT" style="normal" weight="bold"/>
-        </font>
-      </fonts>
-    </renderer>
+  <fonts>
+    <font metrics-url="arial.xml" kerning="yes" embed-url="arial.ttf">
+      <font-triplet name="Arial" style="normal" weight="normal"/>
+      <font-triplet name="ArialMT" style="normal" weight="normal"/>
+    </font>
+    <font metrics-url="arialb.xml" kerning="yes" embed-url="arialb.ttf">
+      <font-triplet name="Arial" style="normal" weight="bold"/>
+      <font-triplet name="ArialMT" style="normal" weight="bold"/>
+    </font>
+  </fonts>
+</renderer>
 
@@ -575,10 +575,11 @@ $(document).ready(function () {
  • The FOP distribution contains a schema for configuration files, at src/foschema/fop-configuration.xsd. Did you validate your configuration file against it? Add the following schema location to the schema element:

    -

    +

    :::xml +

  • and run the configuration file through a validating schema parser. Note that the schema cannot detect all errors, and that it is stricter about the order of some elements than FOP itself is.

    Modified: websites/staging/xmlgraphics/trunk/content/fop/0.95/embedding.html ============================================================================== --- websites/staging/xmlgraphics/trunk/content/fop/0.95/embedding.html (original) +++ websites/staging/xmlgraphics/trunk/content/fop/0.95/embedding.html Tue Dec 4 15:59:34 2012 @@ -341,51 +341,51 @@ $(document).ready(function () {
    -

    Apache™ FOP: Embedding

    +

    Apache™ FOP: Embedding

    How to Embed Apache™ FOP in a Java application

    -

    Overview

    +

    Overview

    Review Running Apache™ FOP for important information that applies to embedded applications as well as command-line use, such as options and performance.

    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. 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.

    -

    Basic Usage Pattern

    +

    Basic Usage Pattern

    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...

    Here is the basic pattern to render an XSL-FO file to PDF:

    -
    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();
    -}
    +
    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();
    +}
     
    @@ -412,20 +412,24 @@ We recently changed FOP's outer API to w

    If you're not totally familiar with JAXP Transformers, please have a look at the Embedding examples 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.

    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 Embedding examples (See "ExampleXML2FO").

    -

    Logging

    +

    Logging

    Logging is now a little different than it was in FOP 0.20.5. We've switched from Avalon Logging to Jakarta Commons Logging . 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. We know this may be an issue in multi-threaded server environments if you'd like to know what's going on in every single FOP processing run. We're planning to add an additional feedback facility to FOP which can be used to obtain all sorts of specific feedback (validation messages, layout problems etc.). "Static logging" is mainly interesting for a developer working on FOP and for advanced users who are debugging FOP. We don't consider the logging output to be useful to normal FOP users. Please have some patience until we can add this feature or jump in and help us build it. We've set up a Wiki page which documents what we're going to build. By default, Jakarta Commons Logging 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 documentation for Jakarta Commons Logging on how to configure alternative backends.

    -

    Processing XSL-FO

    +

    Processing XSL-FO

    Once the Fop instance is set up, call 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() 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.

    -

    Processing XSL-FO generated from XML+XSLT

    +

    Processing XSL-FO generated from XML+XSLT

    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:

    -

    //without XSLT: - //Transformer transformer = factory.newTransformer(); // identity transformer

    -

    //with XSLT: - Source xslt = new StreamSource(new File("mystylesheet.xsl")); - Transformer transformer = factory.newTransformer(xslt);

    -

    Input Sources

    +
    //without XSLT:
    +//Transformer transformer = factory.newTransformer(); // identity transformer
    +
    +//with XSLT:
    +Source xslt = new StreamSource(new File("mystylesheet.xsl"));
    +Transformer transformer = factory.newTransformer(xslt);
    +
    + + +

    Input Sources

    The input XSL-FO document is always received by FOP as a SAX stream (see the Parsing Design Document for the rationale).

    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:

      @@ -452,9 +456,9 @@ By default, Xalan Basic Usage Patterns .

      -

      Configuring Apache FOP Programmatically

      +

      Configuring Apache FOP Programmatically

      Apache FOP provides two levels on which you can customize FOP's behaviour: the FopFactory and the user agent.

      -

      Customizing the FopFactory

      +

      Customizing the FopFactory

      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.

      You can set all sorts of things on the FopFactory:

      - @@ -500,13 +504,13 @@ Set a URIResolver for c

      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.

      -

      Customizing the User Agent

      +

      Customizing the User Agent

      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:

      -
      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);
      +
      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);
       
      @@ -578,34 +582,34 @@ Set a URIResolver for c

      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. You should not reuse an FOUserAgent instance between FOP rendering runs although you can. Especially in multi-threaded environment, this is a bad idea.

      -

      Using a Configuration File

      +

      Using a Configuration File

      Instead of setting the parameters manually in code as shown above you can also set many values from an XML configuration file:

      -
      import org.apache.avalon.framework.configuration.Configuration;
      -import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
      +
      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);
      +DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder();
      +Configuration cfg = cfgBuilder.buildFromFile(new File("C:/Temp/mycfg.xml"));
      +fopFactory.setUserConfig(cfg);
       
      -/* ..or.. */
      +/* ..or.. */
       
      -fopFactory.setUserConfig(new File("C:/Temp/mycfg.xml"));
      +fopFactory.setUserConfig(new File("C:/Temp/mycfg.xml"));
       

      The layout of the configuration file is described on the Configuration page .

      -

      Hints

      -

      Object reuse

      +

      Hints

      +

      Object reuse

      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.

      -

      AWT issues

      +

      AWT issues

      If your XSL-FO files contain SVG then Apache Batik will be used. When Batik is initialised it uses certain classes in java.awt 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.

      The thread means that the Java application may not automatically quit when finished, you will need to call System.exit() . These issues should be fixed in the JDK 1.4.

      If you run into trouble running FOP on a head-less server, please see the notes on Batik .

      -

      Getting information on the rendering process

      +

      Getting information on the rendering process

      To get the number of pages that were rendered by FOP you can call Fop.getResults() . This returns a FormattingResults 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.

      -

      Improving performance

      +

      Improving performance

      There are several options to consider:

      • @@ -624,35 +628,35 @@ Set a URIResolver for c

        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.

      -

      Multithreading FOP

      +

      Multithreading FOP

      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.

      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.

      -

      Examples

      +

      Examples

      The directory "{fop-dir}/examples/embedding" contains several working examples.

      -

      ExampleFO2PDF.java

      +

      ExampleFO2PDF.java

      This example demonstrates the basic usage pattern to transform an XSL-FO file to PDF using FOP.

      Example XSL-FO to PDF

      -

      ExampleXML2FO.java

      +

      ExampleXML2FO.java

      This example 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. Xalan ).

      Example XML to XSL-FO

      -

      ExampleXML2PDF.java

      +

      ExampleXML2PDF.java

      This example 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.

      Example XML to PDF (via XSL-FO)

      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.

      -

      ExampleObj2XML.java

      +

      ExampleObj2XML.java

      This example 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.

      Example Java object to XML

      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).

      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.

      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. An older JAXP tutorial ).

      -

      ExampleObj2PDF.java

      +

      ExampleObj2PDF.java

      This example 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.

      Example Java object to PDF (via XML and XSL-FO)

      -

      ExampleDOM2PDF.java

      +

      ExampleDOM2PDF.java

      This example has FOP use a DOMSource instead of a StreamSource in order to use a DOM tree as input for an XSL transformation.

      -

      ExampleSVG2PDF.java (PDF Transcoder example)

      +

      ExampleSVG2PDF.java (PDF Transcoder example)

      This example shows the usage of the PDF Transcoder, a sub-application within FOP. It is used to generate a PDF document from an SVG file.

      -

      Final notes

      +

      Final notes

      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.

      Modified: websites/staging/xmlgraphics/trunk/content/fop/0.95/extensions.html ============================================================================== --- websites/staging/xmlgraphics/trunk/content/fop/0.95/extensions.html (original) +++ websites/staging/xmlgraphics/trunk/content/fop/0.95/extensions.html Tue Dec 4 15:59:34 2012 @@ -350,8 +350,8 @@ All extensions require the correct use o

      FO Extensions

      Namespace

      By convention, FO extensions in FOP use the "fox" namespace prefix. To use any of the FO extensions, add a namespace entry for http://xmlgraphics.apache.org/fop/extensions to the root element:

      -
      <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"
      -           xmlns:fox="http://xmlgraphics.apache.org/fop/extensions">
      +
      <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"
      +           xmlns:fox="http://xmlgraphics.apache.org/fop/extensions">
       
      @@ -448,7 +448,7 @@ This extension attribute doesn't work fo

      Color functions

      XSL-FO supports specifying color using the rgb(), rgb-icc() and system-color() functions. Apache FOP provides additional color functions for special use cases. Please note that using these functions compromises the interoperability of an FO document.

      cmyk()

      -

      color cmyk(numeric, numeric, numeric, numeric)

      +

      color cmyk(numeric, numeric, numeric, numeric)

      This function will construct a color in device-specific CMYK color space. The numbers must be between 0.0 and 1.0. For output formats that don't support device-specific color space the CMYK value is converted to an sRGB value.

    Modified: websites/staging/xmlgraphics/trunk/content/fop/0.95/fonts.html ============================================================================== --- websites/staging/xmlgraphics/trunk/content/fop/0.95/fonts.html (original) +++ websites/staging/xmlgraphics/trunk/content/fop/0.95/fonts.html Tue Dec 4 15:59:34 2012 @@ -435,10 +435,10 @@ $(document).ready(function () {

    Basic information about fonts can be found at:

    Basic font configuration

    @@ -452,7 +452,7 @@ $(document).ready(function () { <directory recursive="true">C:\MyFonts2</directory> <!-- automatically detect operating system installed fonts --> - <auto-detect/> + <auto-detect/> </fonts>
    @@ -547,7 +547,7 @@ java -cp build\fop.jar;lib\avalon-framew <directory recursive="true">C:\MyFonts2</directory> <!-- automatically detect operating system installed fonts --> - <auto-detect/> + <auto-detect/> </fonts>
    Modified: websites/staging/xmlgraphics/trunk/content/fop/0.95/intermediate.html ============================================================================== --- websites/staging/xmlgraphics/trunk/content/fop/0.95/intermediate.html (original) +++ websites/staging/xmlgraphics/trunk/content/fop/0.95/intermediate.html Tue Dec 4 15:59:34 2012 @@ -350,30 +350,30 @@ $(document).ready(function () {

    As already mentioned, the IF is generated by using the XMLRenderer (MIME type: application/X-fop-areatree ). So, you basically set the right MIME type for the output format and process your FO files as if you would create a PDF file. However, there is an important detail to consider: The various Renderers don't all use the same font sources. To be able to create the right area tree for the ultimate output file, you need to create the IF file using the right font setup. This is achieved by telling the XMLRenderer to mimic another renderer. This is done by calling the XMLRenderer's mimicRenderer() method with an instance of the ultimate target renderer as the single parameter. This has a consequence: An IF file rendered with the Java2DRenderer may not look as expected when it was actually generated for the PDF renderer. For renderers that use the same font setup, this restriction does not apply (PDF and PS, for example). Generating the inte rmediate format file is the first step.

    The second step is to reparse the IF file using the AreaTreeParser which is found in the org.apache.fop.area package. The pages retrieved from the IF file are added to an AreaTreeModel instance from where they are normally rendered using one of the available Renderer implementations. You can find examples for the IF processing in the http://svn.apache.org/viewcvs.cgi/xmlgraphics/fop/trunk/examples/embedding/java/embedding/intermediate/ directory in the FOP distribution

    The basic pattern to parse the IF format looks like this:

    -
    FopFactory fopFactory = FopFactory.newInstance();
    +
    FopFactory fopFactory = FopFactory.newInstance();
     
    -// Setup output
    -OutputStream out = new java.io.FileOutputStream(pdffile);
    -out = new java.io.BufferedOutputStream(out);
    -try {
    -    //Setup fonts and user agent
    -    FontInfo fontInfo = new FontInfo();
    -    FOUserAgent userAgent = fopFactory.newFOUserAgent();
    -
    -    //Construct the AreaTreeModel that will received the individual pages
    -    AreaTreeModel treeModel = new RenderPagesModel(userAgent, 
    -            MimeConstants.MIME_PDF, fontInfo, out);
    -
    -    //Parse the IF file into the area tree
    -    AreaTreeParser parser = new AreaTreeParser();
    -    Source src = new StreamSource(myIFFile);
    -    parser.parse(src, treeModel, userAgent);
    -
    -    //Signal the end of the processing. The renderer can finalize the target document.
    -    treeModel.endDocument();
    -} finally {
    -    out.close();
    -}
    +// Setup output
    +OutputStream out = new java.io.FileOutputStream(pdffile);
    +out = new java.io.BufferedOutputStream(out);
    +try {
    +    //Setup fonts and user agent
    +    FontInfo fontInfo = new FontInfo();
    +    FOUserAgent userAgent = fopFactory.newFOUserAgent();
    +
    +    //Construct the AreaTreeModel that will received the individual pages
    +    AreaTreeModel treeModel = new RenderPagesModel(userAgent,
    +            MimeConstants.MIME_PDF, fontInfo, out);
    +
    +    //Parse the IF file into the area tree
    +    AreaTreeParser parser = new AreaTreeParser();
    +    Source src = new StreamSource(myIFFile);
    +    parser.parse(src, treeModel, userAgent);
    +
    +    //Signal the end of the processing. The renderer can finalize the target document.
    +    treeModel.endDocument();
    +} finally {
    +    out.close();
    +}
     
    Modified: websites/staging/xmlgraphics/trunk/content/fop/0.95/metadata.html ============================================================================== --- websites/staging/xmlgraphics/trunk/content/fop/0.95/metadata.html (original) +++ websites/staging/xmlgraphics/trunk/content/fop/0.95/metadata.html Tue Dec 4 15:59:34 2012 @@ -348,28 +348,28 @@ $(document).ready(function () {

    As noted above, there's no officially recommended way to embed metadata in XSL-FO. Apache™ FOP supports embedding XMP in XSL-FO. Currently, only support for document-level metadata is implemented. Object-level metadata will be implemented when there's interest.

    Document-level metadata can be specified in the fo:declarations element. XMP specification recommends to use x:xmpmeta , rdf:RDF , and rdf:Description elements as shown in example below. Both x:xmpmeta and rdf:RDF elements are recognized as the top-level element introducing an XMP fragment (as per the XMP specification).

    Example

    -
    [..]
    -</fo:layout-master-set>
    -<fo:declarations>
    -  <x:xmpmeta xmlns:x="adobe:ns:meta/">
    -    <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
    -      <rdf:Description rdf:about=""
    -          xmlns:dc="http://purl.org/dc/elements/1.1/">
    -        <!-- Dublin Core properties go here -->
    -        <dc:title>Document title</dc:title>
    -        <dc:creator>Document author</dc:creator>
    -        <dc:description>Document subject</dc:description>
    -      </rdf:Description>
    -      <rdf:Description rdf:about=""
    -          xmlns:xmp="http://ns.adobe.com/xap/1.0/">
    -        <!-- XMP properties go here -->
    -        <xmp:CreatorTool>Tool used to make the PDF</xmp:CreatorTool>
    -      </rdf:Description>
    -    </rdf:RDF>
    -  </x:xmpmeta>
    -</fo:declarations>
    -<fo:page-sequence ...
    -[..]
    +
    [..]
    +</fo:layout-master-set>
    +<fo:declarations>
    +  <x:xmpmeta xmlns:x="adobe:ns:meta/">
    +  <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
    +    <rdf:Description rdf:about=""
    +      xmlns:dc="http://purl.org/dc/elements/1.1/">
    +    <!-- Dublin Core properties go here -->
    +    <dc:title>Document title</dc:title>
    +    <dc:creator>Document author</dc:creator>
    +    <dc:description>Document subject</dc:description>
    +    </rdf:Description>
    +    <rdf:Description rdf:about=""
    +      xmlns:xmp="http://ns.adobe.com/xap/1.0/">
    +    <!-- XMP properties go here -->
    +    <xmp:CreatorTool>Tool used to make the PDF</xmp:CreatorTool>
    +    </rdf:Description>
    +  </rdf:RDF>
    +  </x:xmpmeta>
    +</fo:declarations>
    +<fo:page-sequence ...
    +[..]
     
    @@ -489,16 +489,16 @@ $(document).ready(function () {
    --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscribe@xmlgraphics.apache.org For additional commands, e-mail: commits-help@xmlgraphics.apache.org