Hi,
I m generating PDF file from large XML file using jasper.
Using below code PDF file is generated but taking much time.
So Please suggest some way to reduce this time.
Sample Code
private void generatePDFFromXML(String strJasperFileName, String strXMLContent, String recordPath) {
// Converting xml content into inputstream so, it can use for pdf generation directly without converting it into file
try (InputStream inputStrem = new ByteArrayInputStream(strXMLContent.getBytes("UTF-8"));) {
Locale locale = new Locale("sq");
Map params = new HashMap<>();
params.put(JRParameter.REPORT_LOCALE, locale);
params.put(JRXPathQueryExecuterFactory.XML_INPUT_STREAM, inputStrem);
JRFileVirtualizer virtualizer = new JRFileVirtualizer(2, "tmp");
params.put(JRParameter.REPORT_VIRTUALIZER, virtualizer);
JRXmlDataSource xmlDataSource = new JRXmlDataSource(inputStrem, recordPath);
DefaultJasperReportsContext context = DefaultJasperReportsContext.getInstance();
JRPropertiesUtil.getInstance(context).setProperty(JRXPathExecuterUtils.PROPERTY_XPATH_EXECUTER_FACTORY, "net.sf.jasperreports.engine.util.xml.JaxenXPathExecuterFactory");
context.setProperty(MaxPagesGovernor.PROPERTY_MAX_PAGES_ENABLED, Boolean.TRUE.toString());
context.setProperty(MaxPagesGovernor.PROPERTY_MAX_PAGES, String.valueOf(50000));
context.setProperty(TimeoutGovernor.PROPERTY_TIMEOUT_ENABLED, Boolean.FALSE.toString());
JasperPrint jasperPrint = JasperFillManager.fillReport(strJasperFileName, params, xmlDataSource);
try(FileOutputStream oStream = new FileOutputStream("/Downloads/" + "GeneratedPDF" + ".pdf")){
JRPdfExporter exporter = new JRPdfExporter();
exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(oStream));
SimplePdfReportConfiguration simplePdfReportConfiguration = new SimplePdfReportConfiguration();
simplePdfReportConfiguration.setForceSvgShapes(false);
simplePdfReportConfiguration.setForceLineBreakPolicy(false);
exporter.setConfiguration(simplePdfReportConfiguration);
exporter.exportReport();
byte[] byteOutPut = JasperExportManager.exportReportToPdf(jasperPrint);
oStream.flush();
}
}catch (Exception e) {
e.printStackTrace();
}
}
Thanks in advance.