AnnMary.Thomas Posted November 12, 2014 Share Posted November 12, 2014 How to attach a .pdf file to a generated Jasper reportExample: Say I have 2 jasper files, a.jasper and b.jasper. Now these 2 jasper files are exported as a pdf reportin one single pdf file. tht is Page 1 of the pdf will have a.jasper and page 2 will have b.jasper. Now this I have acheived this by usingJRExporter and passing a.jasper and b.jasper as a list. But there isone more pdf file itself say c.pdf ( not a jasper file, as this is provided by our customer and cannot be created as a japer).Now I want this c.pdf as the 3rd page of the exported pdf report... Link to comment Share on other sites More sharing options...
j.t.casperson Posted January 14, 2016 Share Posted January 14, 2016 Would also like to see this feature Link to comment Share on other sites More sharing options...
dcdacd Posted August 3, 2016 Share Posted August 3, 2016 Somebody knows how can it ? Thanks. Link to comment Share on other sites More sharing options...
AnnMary.Thomas Posted August 4, 2016 Author Share Posted August 4, 2016 This is how I did in Java. Hope this helps ByteArrayInputStream bs = new ByteArrayInputStream(output.toByteArray()); // output refers to your Jasper report Document document = new Document(); PdfCopy copy = new PdfCopy(document, output); document.open(); PdfReader jasperReader; //Reader for Jasper Report PdfReader nonJasperReader; // Reader for the Pdf to be attached (not .jasper file) jasperReader= new PdfReader(bs); attachmentReader = new PdfReader(params.get("att").toString()); numberOfPages = jasperReader.getNumberOfPages(); for (int page = 0; page < numberOfPages;) { copy.addPage(copy.getImportedPage(jasperReader, ++page)); } numberOfPages = nonJasperReader.getNumberOfPages(); for (int page = 0; page < numberOfPages;) { copy.addPage(copy.getImportedPage(nonJasperReader, ++page)); } copy.freeReader(jasperReader); jasperReader.close(); document.close(); } Link to comment Share on other sites More sharing options...
rohitahuja123 Posted August 24, 2016 Share Posted August 24, 2016 Thanks Thomas.However when i see the code, i see only these lines that contribute to the output for my jasper report.It creates a file path for the masterTemplate and then compiles it and fill and then finally export the jasperPrint object, so are you talking about the JasperPrint object ?*****************************************************String masterTemplate = ProductionUtils.createFilePath( config.getSystemProperty( SystemProperty.PATH_KEY ), JRXML_FILE );jasperReport = JasperCompileManager.compileReport( masterTemplate );jasperPrint = JasperFillManager.fillReport( jasperReport, parameters, new JREmptyDataSource() );JasperExportManager.exportReportToPdfFile( jasperPrint, generateLocalFilePath() );***************************************************** Link to comment Share on other sites More sharing options...
rohitahuja123 Posted August 24, 2016 Share Posted August 24, 2016 I called theJasperExportManager.exportReportToPdf(jasperPrint) - method and it returned me byteArray.</pre>1. But what is the output in PdfCopy instance --> its an outStream? :-PdfCopy copy = new PdfCopy(document, output); ?????????2 . And how will i call my PdfReader for the attachmentReader as PdfReader accepts ByteArrayInputStream?3. And after getting the 'copy', how we will pass the exportReportToFile method with a jasperPrint object? Thanks. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now