xmlgraphics-fop-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alexios Giotis <alex.gio...@gmail.com>
Subject Re: Injecting page-height to the FopFactory without creating a new instance
Date Mon, 24 Apr 2017 09:51:56 GMT
Hi Arpit,

This change was intentionally done, see 
https://wiki.apache.org/xmlgraphics-fop/FopFactoryConfiguration <https://wiki.apache.org/xmlgraphics-fop/FopFactoryConfiguration>

The problem is that FopFactory can’t be thread safe and at the same time allow changes in
configuration. In the past, FopFactory was reusable but not thread-safe. Related to “PS”,
we are using FOP 2.1 in several production servers, each one rendering up to 100 documents
at the same time and we don’t have any issue related to thread safety. 

I assume page height and width were configured in FopFactory because in XSL:FO page-height=“auto”
& page-width=“auto” are defined. I suggest to define page-height & page-width
at runtime, for example using an XSLT. The value for page-height & page-width could be
read from an input XML document or passed as a parameter during the transformation.

The following is a slightly changed code copied from 
(a mirror of http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/fop/examples/embedding/java/embedding/ExampleXML2PDF.java?view=markup

    Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);

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

    // Set the value of a <param> in the stylesheet
    transformer.setParameter(“pageHeightParam", “11.00in”);
    transformer.setParameter(“pageWidthParam", “8.5in");

    // Setup input for XSLT transformation
    Source src = new StreamSource(xmlfile);

    // 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);

Hope this helps,
Alexios Giotis

> On 23 Apr 2017, at 06:33, Arpit Phanda <phandaarpit@gmail.com> wrote:
> Hi,
> We are migrating our service from apacheFOP-0.95 to apacheFOP-2.1. Our aim is to configure
pageHeight and pageLength to singleton instance during each rendering call. 
> In earlier version we could create FopFactory instance by calling FopFactory.newInstance()
and then use setPageHeight/setPageWidth on the same instance of FopFactory. Currently, this
is no more valid. Now, we are allowed to set these property on FopFactoryBuilder - new FopFactoryBuilder().setPageHeight().build()
which means we are creating a new FopFactory instance each time. Is there any way of injecting
these property on already created instance.
> PS: Also, i read a few issue where it has been said ApacheFOP is not threadsafe and just
wanted to know the reason behind it.
> -- 
> Regards
> Arpit Phanda

View raw message