Java Program -CSSToXSLFOFilter- blank output

  • ReedH

    ReedH - 2012-10-25

    I am trying to create a Java program that converts an html report to pdf. I am trying to use CSSToXSLFO as part of this. Right now I am just trying to get started on this by simply converting an XML to a XSL FO as in 5.2.1 Example 1. I have not been able to get anything but a blank output file and I cant seem to figure out why. Here is the code, any suggestions?

    public class HTMtoXSLFO {
        public static void
            main(String args) throws Exception {
            SAXParserFactory factory = SAXParserFactory.newInstance();
            CSSToXSLFOFilter filter = new CSSToXSLFOFilter(new File("C:\\Users\\reed henderson\\Documents\\NGP 2013 HARNESS\\report.xml").toURL(),factory.newSAXParser().getXMLReader());
            TransformerHandler handler =((SAXTransformerFactory)TransformerFactory.newInstance()).newTransformerHandler();
            handler.setResult(new StreamResult(new File("C:\\Users\\reed henderson\\Documents\\NGP 2013 HARNESS\\")));
            filter.parse(new InputSource(new FileInputStream("C:\\Users\\reed henderson\\Documents\\NGP 2013 HARNESS\\report.xml")));

  • Werner Donné

    Werner Donné - 2012-10-26


    There should be at least one element with the "region" property set to "body". In the case of XHTML this is set in the User Agent style sheet, but if you use another XML-vocabulary you have to set it yourself.

    Best regards,


  • ReedH

    ReedH - 2012-10-26

    Thanks for the fast reply!

    For now I am just trying to convert an XML file. If I run this on an xhtml file it just errors out…but I would expect that since its not an XML file. but I dont want to mess with that yet.

    I added an element with a "region" property set to "body" but that does not seem to have helped. Here is my xml file I am trying to convert., maybe there is something else wrong with it?


    <?xml version="1.0" encoding="UTF-8"?>
    <report region="body">
    <report title="Harness BOM Report">
       <reportmodule title="">
          <resultsetheader title="DESIGN"/>
          <resultsetheader title="DESCRIPTION"/>
          <resultsetheader title="REV"/>
          <resultsetheader title="RELEASE LEVEL"/>
             <result>HARN - ENG 2013 MX13 NGP</result>
             <result>In Work</result>
       <reportmodule title="">
          <groupBy title="groupingKey"/>
          <resultsetheader title="VAR"/>
          <resultsetheader title="TYPE"/>
          <resultsetheader title="REFDES"/>
          <resultsetheader title="ZONE"/>
          <resultsetheader title="HOUSING"/>
          <resultsetheader title="QTY" accumulateContent="+" type="float"/>
          <resultsetheader title="UNIT"/>
          <resultsetheader title="PACCAR PART NUMBER"/>
          <resultsetheader title="SUPPLIER NAME"/>
          <resultsetheader title="SUPPLIER PART NUMBER"/>
          <resultsetheader title="DESCRIPTION"/>
          <resultsetheader title="MATERIAL"/>
          <resultsetheader title="groupingKey" invisible="true"/>
             <result>3-WAY GT 150-PLUG</result>

    Thanks again,


  • Werner Donné

    Werner Donné - 2012-10-26

    Hi Reed,

    You shouldn't put the attribute "region" on the element, but assign the propery "region" to that element in a stylesheet. You can include the stylesheet as decribed in section 2.1 of the manual.

    Best regards,



Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks