Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
I am trying to fetch records from DB and creating an XML file.
Now, to convert this XML into a PDF file, I have created a routine which uses a style sheet (.xsl) and XML file and uses apache FOP framework and makes a transformer call to create pdf.
Its working fine upto 40 records, but is taking a long time for more records.
Can anyone suggest how to resolve this issue.
Regards,
Shivangi gupta
It's very difficult to help without more details about your routine. The only thing I can think of is that it is a memory issue. Is your method for doing this a static method? If not, it might be an idea to convert it to a static method.
Hi rhall_2_0,
Please find below the routine.
public class pdf{
public static void pdfMethod(String dependentFilePath, String fileOutputXML, String fileOutputPDF) {
OutputStream out=null;
try{
String filePathFlow=dependentFilePath;
StreamSource xmlSource=new StreamSource(new File(fileOutputXML));
FopFactory fopFactory = FopFactory.newInstance(new File(filePathFlow+File.separator+"fop.xconf"));
FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
out= new java.io.FileOutputStream(fileOutputPDF);
out= new java.io.BufferedOuputStream(out);
Fop fop= fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);
TransformerFactory factory = TransformerFactory .newInstance();
String styleSheetFilePath= dependentFilePath+File.separator+"pdf.xsl";
Transformer transformer = factory.newTransformer(new StreamSource (new File(styleSheetFilePath)));
Result res = new SAXResult(fop.getDefaultHandler());
transformer.transform(xmlSource,res);
}catch (Exception e)
{ e.printStackTrace();
}
finally{
IOUtils.closeQuietly(out);
}
}
}
There is clearly a lot going on during the conversion. You will need to add some logging I think to identify where the code slows down. I suspect that this is a memory issue. Have you tried adding more memory to the job?