Quantcast

Injecting page-height to the FopFactory without creating a new instance

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Injecting page-height to the FopFactory without creating a new instance

Arpit Phanda
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Injecting page-height to the FopFactory without creating a new instance

Alexios Giotis
Hi Arpit,

This change was intentionally done, see 

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 


    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 <[hidden email]> 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

Loading...