Apache™ FOP (Formatting Objects Processor) is a print formatter driven by XSL formatting objects (XSL-FO) and an output independent formatter. It is a Java application that reads a formatting object (FO) tree and renders the resulting pages to a specified output. Output formats currently supported include PDF, PS, PCL, AFP, XML (area tree representation), Print, AWT and PNG, and to a lesser extent, RTF and TXT. The primary output target is PDF.

The Apache FOP processor is part of Axional Server core services an can be used for server applications for high performance PDF rendering

You can read more about how to configure Apache™ FOP at:

1 Command line processor

The FOP processor can be used for batch applications by using the following command line:

Copy
$ bin/FOPProcessor.sh -xml {file} -pdf {file} -config {file} [-properties {file}] [-encoding {encoding}]
Argument Description
xml xml file with fo tree
pdf output pdf file
config FOP configuration file
properties FOP UserAgent properties file
encoding file encoding (default is utf-8)

2 FOP server configuration

The Apache™ FOP configuration file is an XML file containing a variety of settings that are useful for controlling FOP's behavior, and for helping it find resources that you wish it to use.

Each server may contain it's own FOP configuration and must indicate where the file is located. This can be done in fopConfig entry in server config.xml file.

In the following example, fopConfig points to conf/fop/userconfig.xml.

Copy
<?xml version="1.0" encoding="UTF-8"?>
<server name="server1" engine="jetty">
    <encoding info="Server encoding">UTF-8</encoding>
    ...
    <fopConfig>conf/fop/userconfig.xml</fopConfig>
    <application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="studioConfig">
      ...
    </application>
</server>

2.1 Fonts

You can use the FOP configuration file to add custom fonts. To do that you should configure the renderer entry. 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.

You must tell FOP how to find and use the font files by registering them in the FOP Configuration. Add entries for your custom fonts, regardless of font type, to the configuration file in a manner similar to the following:

Copy

sample fop configuration file

<?xml version="1.0" encoding="UTF-8"?>
<fop>
    <!-- Font Base URL for resolving relative font URLs -->
    <font-base>fonts</font-base>
 
    <renderers>
        <renderer mime="application/pdf">
            <fonts>
                <font embed-url="FormataPro-Regular.ttf" embedding-mode="subset">
                    <font-triplet name="Formata Pro" style="normal" weight="400"/>
                </font>
                <font embed-url="FormataPro-Italic.ttf" embedding-mode="subset">
                    <font-triplet name="Formata Pro" style="italic" weight="400"/>
                </font>
                <font embed-url="FormataPro-Medium.ttf" embedding-mode="subset">
                    <font-triplet name="Formata Pro" style="normal" weight="700"/>
                </font>
            </fonts>
        </renderer>
    </renderers>
</fop>

2.2 Encryption

FOP supports encryption of PDF output. This feature is commonly used to prevent unauthorized viewing, printing, editing, copying text from the document and doing annotations. It is also possible to ask the user for a password in order to view the contents.

Note that there already exist third party applications which can decrypt an encrypted PDF without effort and allow the aforementioned operations, therefore the degree of protection is limited.

For further information about features and restrictions regarding PDF encryption, look at the documentation coming with Adobe Acrobat or the technical documentation on the Adobe web site.

The following example sets a encryption prolicy for all pdf documents generated using the configuraation file.

Copy
<renderer mime="application/pdf">
  <encryption-params>
     <encryption-length>128</encryption-length>
     <user-password>testuserpass</user-password>
     <owner-password>testownerpass</owner-password>
     <noprint/>
     <nocopy/>
     <noedit/>
     <noannotations/>
     <nofillinforms/>
     <noaccesscontent/>
     <noassembledoc/>
     <noprinthq/>
  </encryption-params>
  
  <fonts>
    ...
  </fonts>
</renderer>

3 FOUserAgent properties

Before rendering a document a set of properties can be send to FOUserAgent instance.

From command line processor properties can be set in a properties file set by argument -properties. The properties file is a standard java properies like

title=the title
author=the author
creator=deister
producer=deister
keywords=key1, key2
Property Type
title string
author string
creator string
producer string
keywords string

You can setup encryption for a given document using the properties file parameters.

Property Type
encrypt boolean
userPassword string
ownerPassword string
allowPrint boolean
allowCopyContent boolean
allowEditContent boolean
allowEditAnnotations boolean
encryptMetadata boolean
allowFillInForms boolean
allowAccessContent boolean
allowAssembleDocument boolean
All encryption parameters will be ignored if encrypt is set to false.

4 List fonts

You can display font (either system and configured) tables so you can check font names, weights and styles invoking the class using the following command:

Copy
$ bin/FOPListFonts.sh -config {file} [-pdf {file}]
+------------+
|fontFamily  |
+------------+
|Courier     |
|Formata Pro |
|Helvetica   |
|Symbol      |
|Times       |
|ZapfDingbats|
+------------+

+------------+---+----------------------------------+----------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|fontFamily  |key|familyNames                       |URL                         |Triplets                                                                                                                                                                                                |
+------------+---+----------------------------------+----------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|Courier     |F9 |[Courier]                         |base14:courier              |[Computer-Modern-Typewriter,normal,400, Courier,normal,400, Monospaced,normal,400, monospace,normal,400]                                                                                                |
|Courier     |F11|[Courier]                         |base14:courier-bold         |[Courier,normal,700, Monospaced,normal,700, monospace,normal,700]                                                                                                                                       |
|Courier     |F12|[Courier]                         |base14:courier-boldoblique  |[Courier,italic,700, Courier,oblique,700, Monospaced,italic,700, Monospaced,oblique,700, monospace,italic,700, monospace,oblique,700]                                                                   |
|Courier     |F10|[Courier]                         |base14:courier-oblique      |[Courier,italic,400, Courier,oblique,400, Monospaced,italic,400, Monospaced,oblique,400, monospace,italic,400, monospace,oblique,400]                                                                   |
|Formata Pro |F16|[Formata Pro, Formata Pro Regular]|FormataPro-Italic.ttf       |[Formata Pro,italic,400]                                                                                                                                                                                |
|Formata Pro |F17|[Formata Pro, Formata Pro Medium] |FormataPro-Medium.ttf       |[Formata Pro,normal,700]                                                                                                                                                                                |
|Formata Pro |F15|[Formata Pro, Formata Pro Regular]|FormataPro-Regular.ttf      |[Formata Pro,normal,400]                                                                                                                                                                                |
|Helvetica   |F1 |[Helvetica]                       |base14:helvetica            |[Helvetica,normal,400, SansSerif,normal,400, sans-serif,normal,400]                                                                                                                                     |
|Helvetica   |F3 |[Helvetica]                       |base14:helvetica-bold       |[Helvetica,normal,700, SansSerif,normal,700, sans-serif,normal,700]                                                                                                                                     |
|Helvetica   |F4 |[Helvetica]                       |base14:helvetica-boldoblique|[Helvetica,italic,700, Helvetica,oblique,700, SansSerif,italic,700, SansSerif,oblique,700, sans-serif,italic,700, sans-serif,oblique,700]                                                               |
|Helvetica   |F2 |[Helvetica]                       |base14:helvetica-oblique    |[Helvetica,italic,400, Helvetica,oblique,400, SansSerif,italic,400, SansSerif,oblique,400, sans-serif,italic,400, sans-serif,oblique,400]                                                               |
|Symbol      |F13|[Symbol]                          |base14:symbol               |[Symbol,normal,400]                                                                                                                                                                                     |
|Times       |F7 |[Times]                           |base14:times-bold           |[Times Roman,normal,700, Times,normal,700, Times-Roman,normal,700, any,normal,700, serif,normal,700]                                                                                                    |
|Times       |F8 |[Times]                           |base14:times-bolditalic     |[Times Roman,italic,700, Times Roman,oblique,700, Times,italic,700, Times,oblique,700, Times-Roman,italic,700, Times-Roman,oblique,700, any,italic,700, any,oblique,700, serif,italic,700, serif,oblique,700]                                                                                                                                                                                                   |
|Times       |F6 |[Times]                           |base14:times-italic         |[Times Roman,italic,400, Times Roman,oblique,400, Times,italic,400, Times,oblique,400, Times-Roman,italic,400, Times-Roman,oblique,400, any,italic,400, any,oblique,400, serif,italic,400, serif,oblique,400]
|Times       |F5 |[Times]                           |base14:times-roman          |[Times Roman,normal,400, Times,normal,400, Times-Roman,normal,400, any,normal,400, serif,normal,400]                                                                                                    |
|ZapfDingbats|F14|[ZapfDingbats]                    |base14:zapfdingbats         |[ZapfDingbats,normal,400]                                                                                                                                                                               |
+------------+---+----------------------------------+----------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
If a pdf file name is specified, a sample document with all font names will be genetated on this file name.