I am trying to create a pdf portfolio by embedding one or more pdf files into a "portfolio" file.
When creating this portfolio file from scratch, with PdfWriter and a Document, the collection is set as expected. However, if I try to set the collection on an already existing pdf document, using PdfStamper, it does not work. Is this expected behavior? Is it possible to set a collection dictionary on an existing document? Is there something I'm missing that prevents the collection dictionary from actually being written out to the document? Here's a code snippet of what I am doing. As an example, I am creating a hidden collection and setting the initial document to the first embedded file. As a new file: byte[] innerDocument = // byte content of document getting embedded. ByteArrayOutputStream outDoc = new ByteArrayOutputStream(); Document doc = new Document(PageSize.LETTER); PdfWriter writer = PdfWriter.getInstance(wrapper, outDoc); doc.open(); PdfCollection coll = new PdfCollection(PdfCollection.HIDDEN); coll.setInitialDocument("document1"); writer.setCollection(coll); PdfFileSpecification fs = PdfFileSpecification.fileEmbedded(writer, null, "file.pdf", innerDocument, false); fs.addDescription("document1", false); writer.addFileAttachment(fs); doc.add(new Paragraph("Some text for cover page.")); doc.close(); writer.close(); This works as expected. However, if I want to use an existing document as the portfolio file, it does not add the collection dictionary: byte[] innerDocument = // byte content of document getting embedded. byte[] outerDocument = // byte content of existing document to embed file into. ByteArrayOutputStream outDoc = new ByteArrayOutputStream(); PdfReader outerDoc = new PdfReader(outerDocument); PdfStamper stamper = new PdfStamper(outerDoc, outDoc); PdfWriter writer = stamper.getWriter(); PdfCollection coll = new PdfCollection(PdfCollection.HIDDEN); coll.setInitialDocument("document1"); writer.setCollection(coll); PdfFileSpecification fs = PdfFileSpecification.fileEmbedded(writer, null, "file.pdf", innerDocument, false); fs.addDescription("document1", false); writer.addFileAttachment(fs); stamper.close(); When the document created by the first method is opened in Acrobat Reader, it immediately opens the embedded file. Also, when viewing the document in a text viewer, the Collection Dictionary can be seen in the document. However, the document created by the second method does not switch immediately to the embedded document. When viewing the created file in a text viewer, the Collection Dictionary cannot be found. -- View this message in context: http://itext-general.2136553.n4.nabble.com/Cannot-set-a-collection-dictionary-from-a-PdfStamper-instance-tp4656890.html Sent from the iText - General mailing list archive at Nabble.com. ------------------------------------------------------------------------------ Everyone hates slow websites. So do we. Make your web apps faster with AppDynamics Download AppDynamics Lite for free today: http://p.sf.net/sfu/appdyn_d2d_nov _______________________________________________ iText-questions mailing list iText-questions@lists.sourceforge.net 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