forrest-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alan Wang <>
Subject Convert xdoc document to PDF
Date Tue, 06 Jul 2010 04:27:06 GMT
Hi All,

I am writing a program similar to pdf output plugin to convert xdoc pages in
xml document ( xdoc similar to,
and would like to generate the pdf output using fop (0.95 on Mac os 10.5) as
shown in the following.  However I am getting the following errors from

(Location of error unknown)
Error(Unknown location): For fo:simple-page-master, fo:region-body must be
declared before fo:region-before.

1. Where can I find the xsl to convert from xdoc to fo. I find one from
apache forrest
distribution( apache-forrest-0.8/main/webapp/skins/common/xslt/fo/document-to-fo.xsl)?
Or Am I using the wrong one for converting from xdoc to fo?

2. Is anything wrong with my code?


public class fop {
 public static void main(String[] args) throws Exception {
     // configure fopFactory as desired
            FopFactory fopFactory = FopFactory.newInstance();

            // configure foUserAgent as desired
            FOUserAgent foUserAgent = fopFactory.newFOUserAgent();

            // Setup output
            OutputStream out = new
            out = new;

            // Construct fop with desired output format
            Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent,

            // Setup XSLT
            TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(new StreamSource(new

            // Set the value of a <param> in the stylesheet
            transformer.setParameter("versionParam", "2.0");

            // Setup input for XSLT transformation
Source src = new StreamSource("

            // Resulting SAX events (the generated FO) must be piped through
to FOP
            Result res = new SAXResult(fop.getDefaultHandler());

            // Start XSLT transformation and FOP processing
            transformer.transform(src, res);


View raw message