|
I am trying to concatenate two pdf files, however when the file created is opened I get the error 'There was an error opening the document. The file is damaged and could not be repaired.' My code is almost exactly taken from concat_pdf, can anyone see where i went wrong?
public void generatePDF(FileOutputStream fos) { try {
int f = 0; Document document = null; PdfCopy writer = null; PdfReader reader = null; String[] args = {"confirmation01.pdf", "billing01.pdf"}; while (f < 2) { reader = new PdfReader(args[f]);
int n = reader.getNumberOfPages(); System.out.println("There are " + n + " pages in " + args[f]);
document = new Document(reader.getPageSizeWithRotation(1)); writer = new PdfCopy(document, fos); writer.setPageCount(2); document.open();
PdfImportedPage page; for (int i = 0; i < n; ) { ++i; page = writer.getImportedPage(reader, i); writer.addPage(page); System.out.println("Processed page " + i); } f++; } document.close(); writer.close(); } catch(Exception e) { e.printStackTrace(); } }
Thanks in advance
Timothy Smith CGI 5099 Creekbank Rd. Phone: (905)282-3532 Cell: (905)866-4970
|
- Re: [iText-questions] Problem concatinating pdfs Smith, Tim
- Re: [iText-questions] Problem concatinating pdfs Paulo Soares
