is it possible to concat 2 or more pdf file

By: Shah Sangeeta S - shah_sangeeta
is it possible to concat 2 or more pdf file
2003-07-23 02:38
i have created a reports in pdf formats
StringBuffer sb = new StringBuffer();

for(; ; ){
byte[] bytes = JasperRunManager.runReportToPdf( reportFile.getPath(), parameters , getConnection());
sb.append(new String(bytes));
FileOutputStream fout = new FileOutputStream("invoice.pdf" );
when i view invoice.pdf it shows me right file size but displays me last pdf generated in above loop.This is because JasperRunManager.runReportToPdf() it put's
%PDF-1.4---startfile tag
%%EOF---end file tag.
I want to merge this file is it possible with any other class api

By: Gregory A. Swarthout - gswarthout
RE: is it possible to concat 2 or more pdf fi
2003-07-23 09:21
iText (which comes with JasperReports) can be used to concat two (or more) PDF files.

By: juan david vergara perez - jvergara
RE: is it possible to concat 2 or more pdf file
2003-07-23 12:12
this is a sample, i think is very simple and not is necessary to modify the JRPdfExporter

JasperPrint jasperPrint = JasperFillManager.fillReport(plantillaJasper, parametros, objeto);

return null;
JasperPrint jasperPrintCopy = JasperFillManager.fillReport(plantillaJasper,parametros, ((VectorDataSource)objeto).moveFirst());

//Se adicionan las paginas de la facctura copia.
Object[] paginasCopy = jasperPrintCopy.getPages().toArray();
for (int i = 0;i<paginasCopy.length;i++)

return JasperExportManager.exportReportToPdf(jasperPrint);

By: Jason Essington - essington
RE: is it possible to concat 2 or more pdf file
2003-07-23 10:58
I have modified Teodor's JRPdfExporter for exactly this purpose. It takes as a parameter a list of JasperPrint objects and creates one pdf file, with "bookmarks" for the start of each report.

I have also modified JRXlsExporter to perform a similar function (multiple reports in the same xls file)

If you are interested, I will be happy to submit the files to the patches section of the sourceforge site.

The JRXlsBatchExporter requires a newer version of POI to work properly, but both batch exporters work quite nicely. In fact they function as replacements for the standard JRPdfExporter and JRXlsExporter, since their behavior in the absense of a JRBatchExporterParameter.JASPER_PRINT_BATCH parameter (a list of JasperPrint objects) they revert to single report behavior.

the only draw back is that you will have compile/fill the report yourself (without the use of the JasperRunManager) to compile the list of JasperPrint Objects.


By: Chuck Deal - cdeal
RE: is it possible to concat 2 or more pdf file
2003-07-24 05:04
I'd like to take a look at your Batch Exporters if you could post them to the Patches section.


By: Jason Essington - essington
RE: is it possible to concat 2 or more pdf file
2003-07-29 11:27
Done, patch #779751


By: Shah Sangeeta S - shah_sangeeta
RE: is it possible to concat 2 or more pdf file
2003-07-24 05:43
thanks all .
i am now able to concat 2 or more pdf file and save on the server in pdf format.
now i have to show this generated pdf file on client side using byte[].i am using paching technology of servlet.i have one gateway servlet and java classes.My gateway servlet is setting the res.setContentType("application/pdf");
i did this and it did work but
FileInputStream fin new FileInputStream("invoice.pdf");
int len=fin.available();
byte b[]= new byte[len];;
but my pdf file is big.and i cannot use
int len=fin.available();

StringBuffer sb = new StringBuffer();
BufferedReader buf = new BufferedReader(new InputStreamReader(new FileInputStream("invoice.pdf")));
String str=buf.readLine();
i am able to open pdf file on browser but when pdf file get open on client system it show an error message..pdf is corrupted and couldnot be repair.
can anybody have a solution.

By: Ryan Johnson - delscovich
RE: is it possible to concat 2 or more pdf file
2003-07-30 10:31
The JavaDoc on BufferedReader.readln() explains that "A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a linefeed," and that it returns "A String containing the contents of the line, <b>not including any line-termination characters</b>. "

This works great for reading in text line by line, but in a pdf file, the '\n' and '\r' chars are part of the data!

Try this instead:
File file = new File("invoice.pdf");
BufferedInputStream in = new BuferedInputStream(new FileInputStream(file));
ByteArrayOutputStream out = new ByteArrayOutputStrem((int) file.length());
byte[] buf = new byte[1000];
while(true) {
int count =;
if(count < 0)
break; // eof
if(count == 0)
continue; // nothing ready this time

out.write(buf, 0, count); // only write the bytes that were actually read in

Good luck,
2002 JI Open Discussion's picture
Joined: Aug 10 2006 - 3:28am
Last seen: 16 years 10 months ago

0 Answers:

No answers yet