The values of EmbeddedFiles is a Names Tree - so it can have both Names and Kids in any combination
Leonard On 2/28/13 11:33 PM, "sselvia" <ssel...@gmail.com> wrote: >Using the code below I'm trying to extract an embedded PDF which I can >see in >Reader. The problem I'm having is the PdfArray file specs = embedded >files.getAsArray(PdfName.NAMES); The content of the embeddedfiles is an >KIDS item not NAMES. If I change the code to be KIDS and execute the rest >of the code the refs item is null. In the catalog a COLLECTION item does >exist, is there an example using the COLLECTION item that will allow me to >extract the embedded PDF. > >PdfReader reader = new PdfReader(filename); > PdfDictionary root = reader.getCatalog(); > PdfDictionary documentnames = root.getAsDict(PdfName.NAMES); > PdfDictionary embeddedfiles = >documentnames.getAsDict(PdfName.EMBEDDEDFILES); > PdfArray filespecs = embeddedfiles.getAsArray(PdfName.NAMES); > PdfDictionary filespec; > PdfDictionary refs; > FileOutputStream fos; > PRStream stream; > for (int i = 0; i < filespecs.size(); ) { > filespecs.getAsString(i++); > filespec = filespecs.getAsDict(i++); > refs = filespec.getAsDict(PdfName.EF); > for (PdfName key : refs.getKeys()) { > fos = new FileOutputStream(String.format(PATH, >filespec.getAsString(key).toString())); > stream = (PRStream) >PdfReader.getPdfObject(refs.getAsIndirectObject(key)); > fos.write(PdfReader.getStreamBytes(stream)); > fos.flush(); > fos.close(); > } > } > reader.close(); > > > >-- >View this message in context: >http://itext-general.2136553.n4.nabble.com/Extract-PDF-from-a-PDF-Collecti >on-tp4657711.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_feb >_______________________________________________ >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 ------------------------------------------------------------------------------ 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_feb _______________________________________________ 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