Hello,
I'm trying to recreate a PDF by reading it and rebuild it as a new
document using the attached code.
The original file contains layers (Optional Content Groups = OCG) which
were introduced with PDF-1.5. This almost works except that layers
disappear in the final output.
What am I doing wrong?
I'm using iText 2.1.7 (yes, it's old but it's at least unencumbered by
licensing problems)
Here is the essential code
--------------
PdfReader reader = new PdfReader(pdf);
Document document = new Document(PageSize.A4);
ByteArrayOutputStream os = new ByteArrayOutputStream();
PdfWriter writer = PdfWriter.getInstance(document, os);
writer.setPdfVersion(PdfWriter.PDF_VERSION_1_5);
document.open();
PdfContentByte cb = writer.getDirectContent();
int n = reader.getNumberOfPages();
for (int i = 1; i <= n; i++) {
PdfImportedPage page = writer.getImportedPage(reader, i);
cb.addTemplate(page, 1, 1);
document.newPage();
}
document.close();
return os.toByteArray();
------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
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