Jump to content

How to reduce time to generate PDF from large XML?


Recommended Posts


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

                byte[] byteOutPut = JasperExportManager.exportReportToPdf(jasperPrint);
        }catch (Exception e) {


Thanks in advance.

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...