Hi,
In the previous post I posted a wrong method. I had a method with the same
name but with different parameters ... sorry about that...
This is the method (it receives a list of Files and concatenate them with
PdfCopy, saving it to outputFile)
public static void concatenate(List<File> pdfFiles, File outputFile)
throws Exception {
FileOutputStream outputStream;
try {
outputStream = new FileOutputStream(outputFile);
} catch (FileNotFoundException e) {
throw new Exception("Error opening output stream");
}
boolean first = true;
Document document = new Document();
PdfCopy pdfCopier = null;
try {
pdfCopier = new PdfCopy(document, outputStream);
pdfCopier.setPdfVersion(PdfWriter.PDF_VERSION_1_3);
} catch (DocumentException e) {
throw new Exception("Error creating pdfCopy");
}
document.open();
for(File itemFile : pdfFiles) {
PdfReader pdfReader = null;
try {
pdfReader = new PdfReader(itemFile.toURL());
pdfReader.consolidateNamedDestinations();
// update page offset
int numberOfPages =
pdfReader.getNumberOfPages();
// If first source document, create document
and copier
if (first) {
document.setPageSize(pdfReader.getPageSizeWithRotation(1));
first = false;
}
// Add all read pages to document
PdfImportedPage importedPage;
for (int i = 1; i <= numberOfPages; i++) {
importedPage =
pdfCopier.getImportedPage(pdfReader, i);
pdfCopier.addPage(importedPage);
}
PRAcroForm form = pdfReader.getAcroForm();
if (form != null)
pdfCopier.copyAcroForm(pdfReader);
} catch (IOException e) {
addErrorPage(outputStream, e);
LOGGER.error(e);
} catch (DocumentException e) {
addErrorPage(outputStream, e);
LOGGER.error(e);
} finally {
if (pdfReader != null)
pdfReader.close();
}
}
document.close();
}
--
View this message in context:
http://itext-general.2136553.n4.nabble.com/setting-pdf-version-with-PdfCopy-tp3596760p3596833.html
Sent from the iText - General mailing list archive at Nabble.com.
------------------------------------------------------------------------------
EditLive Enterprise is the world's most technically advanced content
authoring tool. Experience the power of Track Changes, Inline Image
Editing and ensure content is compliant with Accessibility Checking.
http://p.sf.net/sfu/ephox-dev2dev
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples:
http://itextpdf.com/themes/keywords.php