XML to PDF

Convert XML to PDF Getting XML to PDF is a common requirement for report generation applications because the PDF file format is a convenient, well-supported and well-documented cross-platform mechanism for publishing documents. Stylus Studio® includes several different ways to convert XML to PDF documents.

XSL-FO to PDF

The most straight-forward way to produce a PDF from XML is to write in a syntax known as XSL-FO. This is a set of formatting instructions in XML which, when rendered through a formatter, will produce a PDF. RenderX XEP and Apache FOP are both implementations of FO engines.

Here is a sample XSL-FO file that will produce the centered message "Hello, World!" on a typical American-style 8½"×11" page:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
        <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
            <fo:layout-master-set>
                <fo:simple-page-master master-name="Letter" page-height="11in" page-width="8.5in">
                    <fo:region-body region-name="only_region" margin="1in" background-color="#CCCCCC"/>
                </fo:simple-page-master>
            </fo:layout-master-set>
            <fo:page-sequence master-reference="Letter">
                <fo:flow flow-name="only_region">
                    <fo:block text-align="center">Hello, World!</fo:block>
                </fo:flow>
            </fo:page-sequence>
        </fo:root>
    </xsl:template>
</xsl:stylesheet>

Converting XML to PDF using XSL:FO

But that looks messy, so we've made it easier in a variety of ways.

XSL-FO Editor

First, as you can see by the color-coding above, the Stylus Studio® Sense:X technology is available to help in making the XSL-FO text valid. Sense:X knows the XSL-FO vocabulary - which attributes and elements belong where - which makes you job easier. But it could be easier still...

XML to PDF Screenshot showing XSL Editor (Click to enlarge)
(click to enlarge)

Generate PDF from XSLT and XQuery

The XML Report module allows you to visually design your stylesheets, and then generate the XSLT or XQuery that writes XSL-FO. Combined with one of the included engines you can go from a visual environment to PDF in one step.

For the above example, all you need to do is type "Hello, World!" into the XML Report module and press the generate button. Choose XSLT 1.0, XSLT 2.0 or XQuery, and an output mode of XSL-FO, and off we go to generate the code for you.

XML to PDF Dialog showing FO engines (Click to enlarge)
(click to enlarge)

RenderX XEP

For serious production-quality XSL-FO work, RenderX makes an XSL-FO processor called XEP. Stylus Studio® bundles a copy of the personal edition, so that you may develop and test your documents and see how they would look in the field.

Apache FOP

The Apache project has produced an open-source FO processor called FOP. We bundle it with Stylus Studio®, and you can choose to use it for converting XSL-FO to PDFs.

DocBook to PDF

The DocBook.org website includes a set of schemas for formatting technical documents. An open-source project called, oddly enough, The DocBook Project" has produced a set of stylesheets which will convert DocBook XML to PDF. (An archived copy of the XSLT code and documentation can be found here.)

WordML to PDF

Microsoft has produced an storage format for Word that saves the documents in XML. RenderX has in turn produced a set of stylesheets that will transform WordprocessingML to XSL-FO suitable for processing with the XEP engine.

Remember that Stylus Studio® includes the RenderX XEP engine, so that you may test this by downloading a copy of Stylus Studio® right now, and then getting the freely-available stylesheet from RenderX.

Adobe Indesign INX to PDF

Similar to the above, RenderX also has made freely available stylesheets to convert the Adobe Indesign INX documents into XSL-FO.

After downloading a copy of Stylus Studio® from here, go to to download the INX to XSL-FO stylesheet.

DITA to PDF

The Darwin Information Typing Architecture is another powerful XML publishing framework. It is comparable to DocBook in scope, but where DocBook is designed for narrative formats, such as books or articles, DITA has strengths in large interrelated documentation sets. The DITA Open Toolkit project includes transforms to convert DITA XML to XSL-FO, which again can be rendered to PDF.

XML to PDF Mapper

RenderX has also made available an XSL-FO DTD (archive copy) suitable for using as a target for the Stylus Studio® XML Mapper.

As you can see, we have a plethora of XML to PDF transformation mechanisms — for generating and using XSL-FO to produce PDFs. Some, like the XML Report tool, completely hide the XSL-FO and PDF details from you; others, like the XML Editor, give you full control of every character. Whatever level you wish to work, downloading a copy of Stylus Studio® today will get your XML to PDF in no time at all.

PURCHASE STYLUS STUDIO ONLINE TODAY!!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Try Stylus XML and PDF Tools

Simplify XML to PDF conversion using Stylus Studio®'s award-winning XML publishing tools — Download a free trial of our today!

What's New for X15?

New XQuery & Web Services Tools, Support for MySQL, PostgreSQL, HL7 EDI, Microsoft .NET Code Generation and much more!

Ask Someone You Know

Does your company use Stylus Studio? Do your competitors? Engineers from over 100,000 leading companies use Stylus Studio, and now you can ask someone from your own organization about their experiences using Stylus Studio.

 
Free Stylus Studio XML Training:
W3C Member