XMLMill - convert xml to pdf with java. Generate PDF from xml/xsl.

XMLMill User Guide

Version: 3.00 Date: January 2nd, 2008
This tutorial is opened in a separate window in order to maximize the legibility of this tutorial.
To return to XMLMill, close this browser window

This page as PDFPrinter friendly pageThis guide (!) as PDF



XMLMill for Java is intended for software developers who want to generate .pdf documents from xml and/or xsl.

XMLMill can be used standalone or be integrated into your applications (standalone / webbased) that need to generate .pdf documents.

XMLMill is specifically designed for 'high volume xml/xsl to PDF generation'. The 'high volume' is regarding to:

Large .pdf documents

XMLMill is capable of generating large .pdf documents (+ 1.000 pages) without running out of memory.

Large quantity of .pdf documents

XMLMill is capable of generating a high volume of .pdf documents (+ 100.000 documents) without running out of memory.

Multi-threading ready

XMLMill is multi-threading ready, meaning it can take advantage of running on computers with multiple processors and balancing the workload over the processors..


Conceptual Model

The following diagram shows the conceptual model.

Select to enlarge

The xml source and xsl stylesheet are sent to XMLMill to be transformed to a .pdf document. Internally, a .mill Document is generated containing all formatting instructions (based on the xsl stylesheet) and data (based on the xml source) needed to generate a .pdf document. Following happens: :

  1. A xml-source containing your data is sent to XMLMill together with a xsl stylesheet. The xml source contains the data to be published. The xsl file contains the formatting and transformation instructions needed for converting the data to an internal .mill Document.
  2. The XMLMill application will convert your xml source, based on your xsl specifications, to an internal .mill file. The .mill file should be compliant with the xmlmill.xsd specification.
  3. The generated internal .mill file will be used to generate the PDF document(s).

Look at following example:

Suppose you have following xml file:

[002]                         A XML document:
[004] <?xml version="1.0" encoding="UTF-8"?>
[005] <?xml-stylesheet type="text/xsl" href="example.xsl"?>
[006] <data>
[007]   <block>
[008]      Hello World
[009]   </block>
[010] </data> 

Now you will need to have a XSL file that will :

  1. Transform the elements in this xml file to elements compliant with the xmlmill.dtd specification (for example: transform the <block> element to a <p> paragraph defined in the xmllmill.dtd specification).
  2. Add formatting instructions (font-size, alignment, ...).

Below is an example of a possible XSL file:

[002]                         A XSL document:
[004] <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0" 
      xsi:schemaLocation="http://www.xmlmill.com/XSL/Format xmlmill.xsd">    
[008]   <xsl:output method="xml" indent="yes" encoding="UTF-16"/>
[010]   <xsl:template match="/">
[011]     <ml:documents whitespace-collapse="on" space-collapse="on"> 
[012]       <ml:document file="output/test.pdf">
[013]         <ml:layout-master-set>
[014]           <ml:simple-page-master master-name="main"  margin="10pt">
[015]             <ml:region-body border-style="solid"  margin="2cm"/>
[016]           </ml:simple-page-master>
[017]         </ml:layout-master-set>
[018]         <ml:page-sequence initial-page-number="91" 
[020]           <ml:flow flow-name="xsl-region-body">
[021]             <ml:p align="center" 
[022]                color="blue"
[023]                font-type="type1" 
[024]                font-family="helvetica" 
[025]                font-style="italic" 
[026]                font-size="36pt" >
[027]             <xsl:value-of select="data/block"/><ml:/p>      
[028]           </ml:flow>
[029]         </ml:page-sequence>
[030]       </ml:document>
[031]     </ml:documents>            
[032]   </xsl:template>
[033] </xsl:stylesheet>

The xml stylesheet will transform the xml source to following .mill document:

[002]                         The .MILL document:
[004] <?xml version="1.0" encoding="UTF-8"?>
[005] <ml:documents xmlns:ml="http://www.xmlmill.com/XSL/Format"
[006]                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
[007]                  xsi:schemaLocation="http://www.xmlmill.com/XSL/Format 
[009]   <ml:document file="output/test.pdf">
[010]         <ml:layout-master-set>
[011]           <ml:simple-page-master master-name="main" page-width="595" 
                page-height="842" margin="10pt">
[013]             <ml:region-body border-style="solid" column-count="1" 
                  margin-bottom="2cm" margin-top="2cm"/>
[015]           </ml:simple-page-master>
[016]         </ml:layout-master-set>
[017]         <ml:page-sequence initial-page-number="91" 
[019]           <ml:flow flow-name="xsl-region-body">
[020]           <ml:p align="center" color="blue" font-style="italic" 
[022]             Hello World
[023]           <ml:/p>
[024]       </ml:flow>
[025]     </ml:page-sequence>
[026]   </ml:document>
[027] </ml:documents>

The .mill document contains all elements and attributes XMLMill understands to convert it to a .pdf document:

Select to enlarge

Implementation Model

The following diagram shows the implementation model:

Select to enlarge

The xml source and xsl stylesheet are sent to XMLMill in a variey of ways (as a File, Stream, URL or DOMSource) to a com.xmlmill.JAXPTransformer instance.

The data are converted to javax.xml.transform.Source objects and sent to the javax.xml.transform.Transformer instance.

Using callbacks, the data is sent to the com.xmlmill.PDXTransformHandler instance.

PDEElements, which represents objects in a document (header, footer, image, paragraphs, ...) are genererated.

The PDEElements build the PDF document.


If you have questions, please do not hesitate to send a mail to support@xmlmill.com.

  • All the examples in this userguide can be found in the samples/ directory in the download.
Copyright © 2001 - 2012. All rights reserved. XMLMill and XMLMill logo are trademarks of Pecunia Data Systems, bvba.
Powered by Apache CocoonPowered by XMLMill