Fop fop = 
fopFactory.newFop(MimeConstants.MIME_TIFF,fopFactory.newFOUserAgent(),outputStream);



I am not sure as each records need to generate one file. So,How do we use same 
Fop object for each outputstream?


---Original---
From: "Simon Steiner"<simonsteiner1...@gmail.com&gt;
Date: Tue, Jun 4, 2024 22:04 PM
To: "fop-users"<fop-users@xmlgraphics.apache.org&gt;;
Cc: "18224494266"<<18224494...@163.com&gt;&gt;;
Subject: RE: Fop batch generate report performance



Hi,

&nbsp;

What about reusing the fopfactory, 1 per thread.

&nbsp;

Thanks

&nbsp;

From: 孤王 <1289495...@qq.com.INVALID&gt; 
Sent: 04 June 2024 14:49
To: fop-users <fop-users@xmlgraphics.apache.org&gt;
Cc: 18224494266 <18224494...@163.com&gt;
Subject: Fop batch generate report performance

&nbsp;

Dear Fop Docters,


&nbsp;


I am a student of Fop. May I ask some question for run the batch reports by 
Fop? Our company using the Fop to generate TIFF file. found the TIFF file 
cannot load font by lazy font. So, it will load all of the config folder fonts.

<renderer mime="image/tiff"&gt;


&nbsp; <directory recursive = "true"&gt;/tmp/fonts</directory&gt;


&nbsp; <compression&gt;CCITT T.6</compression&gt;


&nbsp; <endianness&gt;LITTLE_ENDIAN</endianness&gt;


</renderer&gt;



&nbsp;


As our company all fonts more than 200M. So, when run the batch data(which 
records more 10000 each request). it mean one batch request will loop 10k times 
to create 10K Fop objects( fopFactory.newFop(...)). Each record of the batch 
need to load the font again. it lead to the generate is too slow.&nbsp;


&nbsp;


Could you give me some advise for new Fop object&nbsp;Repeatedly loading fonts 
for each record of one batch(one batch has 10k records need to loop).
Our found the Repeatedly loading fonts of Fop core code. As attachment picture 
"Fop custom load font code.PNG".
Our service code example as below.
@Override
public boolean fopGen(RequestData requestData, Templates templates) {
&nbsp;&nbsp;&nbsp; // one batch loop more than 10000 records.
&nbsp;&nbsp;&nbsp; requestData.getData().forEach(singleData -&gt;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String xmlData = 
convertJson2Xml(singleData);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
generateFopFactory(xmlData,templates);
&nbsp;&nbsp;&nbsp; });
&nbsp;&nbsp;&nbsp; return true;
}
private void generateFopFactory(String xmlData, Templates templates){
&nbsp;&nbsp;&nbsp; FopFactory fopFactory = createFopFactory();
&nbsp;&nbsp;&nbsp; try(ByteArrayInputStream inputStream = new 
ByteArrayInputStream(xmlData.getBytes());
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ByteArrayOutputStream outputStream = 
new ByteArrayOutputStream()){
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Source src;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; src = new StreamSource(inputStream);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Fop fop = 
fopFactory.newFop(MimeConstants.MIME_TIFF,fopFactory.newFOUserAgent(),outputStream);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Transformer transformer = 
templates.newTransformer();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; final List<String&gt; errList = new 
ArrayList<&gt;();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; transformer.setErrorListener(new 
FopErrorListener());
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Result res = new 
SAXResult(fop.getDefaultHandler());
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; transformer.transform(src,res);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; convert2File(outputStream);
&nbsp;&nbsp;&nbsp; } catch (IOException e) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; e.printStackTrace();
&nbsp;&nbsp;&nbsp; } catch (FOPException e) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; e.printStackTrace();
&nbsp;&nbsp;&nbsp; } catch (TransformerConfigurationException e) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; e.printStackTrace();
&nbsp;&nbsp;&nbsp; } catch (TransformerException e) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; e.printStackTrace();
&nbsp;&nbsp;&nbsp; }
}&nbsp;

Reply via email to