matthew.kellar Posted June 5, 2018 Share Posted June 5, 2018 Hello there!Ok, so I've got a tricky one. I've got a report that has multiple subreports. Each one of those subreports contains a report group that puts each data element onto a new page, then the master report compiles all of those into a single PDF. I need a way to instead generate a separate PDF file for each record, while still only making 1 rest call. I also need to be able to dynamically change the PDF names to match the data element value. Any ideas? Link to comment Share on other sites More sharing options...
Solution hozawa Posted June 6, 2018 Solution Share Posted June 6, 2018 https://stackoverflow.com/questions/12688778/increase-tomcat-memory-settingsJasperReports only output 1 pdf per report. You'll have to create your own program that uses JasperReports library to do that.I've done what you've asked before several times so I'm definitely sure that it's possible if you build your own program. Link to comment Share on other sites More sharing options...
matthew.kellar Posted June 6, 2018 Author Share Posted June 6, 2018 @hozawa, thank you for the response, but it looks like that link is unrelated, do you have another link? Link to comment Share on other sites More sharing options...
reportdev Posted June 6, 2018 Share Posted June 6, 2018 @Matthew... remove the Correct Answer Tag from Hozawa's post if you feel you did not get the answer,so that Other users can comment on this post. Otherwise it not allowing other users to answer.Below is the code that i wrote in java for the same purpose... try to salvage some code and write your own scriptlet in jasper reports./*Imports :Commons-beanutilsCommons-digesterCommons-loggingJasperreportsOjdbcOrg.apache.commons.collections */ import java.io.FileOutputStream;import java.io.IOException;import java.sql.Connection;import java.sql.DriverManager;import java.sql.SQLException;import java.util.HashMap;import java.util.Map;import javax.swing.JFrame;import com.lowagie.text.Document;import com.lowagie.text.DocumentException;import com.lowagie.text.pdf.PdfCopy;import com.lowagie.text.pdf.PdfImportedPage;import com.lowagie.text.pdf.PdfReader;import com.lowagie.text.pdf.PdfWriter;import net.sf.jasperreports.engine.JRException;import net.sf.jasperreports.engine.JasperFillManager;import net.sf.jasperreports.engine.JasperPrint;import net.sf.jasperreports.engine.JasperReport;import net.sf.jasperreports.engine.export.JRPdfExporter;import net.sf.jasperreports.engine.util.JRLoader;import net.sf.jasperreports.export.ExporterInput;import net.sf.jasperreports.export.SimpleExporterInput;import net.sf.jasperreports.export.SimpleOutputStreamExporterOutput;import net.sf.jasperreports.export.SimplePdfExporterConfiguration;import net.sf.jasperreports.swing.JRViewer;public class JasperReportFillWithSplitPDF { @SuppressWarnings("unchecked") public static void main(String[] args) throws SQLException, IOException, DocumentException { try { Connection con = DriverManager.getConnection("jdbcConnectionStrings); // opens a jdbc connection String reportName = "reportJrxml"; JasperReport report = (JasperReport) JRLoader.loadObjectFromFile("C:/" + reportName + ".jasper"); Map parameters = new HashMap(); JasperPrint jasperPrint = JasperFillManager.fillReport(report, parameters, con); JFrame frame = new JFrame("Report"); frame.getContentPane().add(new JRViewer(jasperPrint)); frame.pack(); frame.setVisible(true); JRPdfExporter exporter = new JRPdfExporter(); ExporterInput inp = new SimpleExporterInput(jasperPrint); exporter.setExporterInput(inp); exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(reportName + ".pdf")); SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration(); configuration.setPermissions(PdfWriter.ALLOW_PRINTING | PdfWriter.ALLOW_COPY); exporter.setConfiguration(configuration); exporter.exportReport(); exporter.setExporterOutput(null); String inFile = new String(reportName + ".pdf"); PdfReader reader = new PdfReader(inFile); int n = reader.getNumberOfPages(); int i = 0; while ( i < n ) { String outFile = inFile.substring(0, inFile.indexOf(".pdf")) + "-" + String.format("%03d", i + 1) + ".pdf"; System.out.println ("Writing " + outFile); Document document = new Document(reader.getPageSizeWithRotation(1)); PdfCopy writer = new PdfCopy(document, new FileOutputStream(outFile)); document.open(); PdfImportedPage page = writer.getImportedPage(reader, ++i); writer.addPage(page); document.close(); writer.close(); } } catch (JRException e) { e.printStackTrace(); } }} 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