I want the same, and searched about 6 hours now. I've made a little example pdf:
pdftk b.pdf attach_files a.txt a.edi output a.pdf I suppose the result are document level attachments. I'am working with iText 2.1.7, and tried the following code with iText-toolbox-2.1.7.jar: import java.io.IOException; import com.lowagie.text.pdf.PdfDictionary; import com.lowagie.text.pdf.PdfName; import com.lowagie.text.pdf.PdfReader; import com.lowagie.toolbox.plugins.ExtractAttachments; public class ExtractPdf { public static void main(String[] args) throws IOException{ PdfReader reader = new PdfReader("/tmp/a.pdf"); PdfDictionary root = reader.getCatalog(); PdfDictionary names = (PdfDictionary)PdfReader.getPdfObject(root.get(PdfName.NAMES)); PdfDictionary files = (PdfDictionary) PdfReader.getPdfObject(names.get(PdfName.EMBEDDEDFILES)); try { ExtractAttachments.unpackFile(reader, files, "/tmp/"); } catch (Exception e) { e.printStackTrace(); } } } But nothing happens. I expected a.txt and a.edi in /tmp/. I took a look at the doc http://www.docjar.com/docs/api/com/lowagie/toolbox/plugins/ExtractAttachments.html#execute and the source, too, but have no idea. I've also tried your posted example from iText 5.x http://itextpdf.com/tutorials.php?branch=tutorials.attachments&node=doclevel with iText 2.1.7, but Eclipse shows the error "Type mismatch: cannto convert from element type object to PdfName" for the line: for (PdfName key : refs.getKeys()) { I also take a look at all results for the keyword extract attachment/embedded in this mailinglist. The answer are always the same. Use the toolbox or look at this example. It's frustrating, that I don't got it. It's a simple onliner with PdfTk, which uses iText under the hood. So it should work. But what did I wrong? -- View this message in context: http://itext-general.2136553.n4.nabble.com/How-to-extract-embedded-file-tp2247128p2260125.html Sent from the iText - General mailing list archive at Nabble.com. ------------------------------------------------------------------------------ ThinkGeek and WIRED's GeekDad team up for the Ultimate GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the lucky parental unit. See the prize list and enter to win: http://p.sf.net/sfu/thinkgeek-promo _______________________________________________ iText-questions mailing list iText-questions@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/itext-questions Buy the iText book: http://www.itextpdf.com/book/ Check the site with examples before you ask questions: http://www.1t3xt.info/examples/ You can also search the keywords list: http://1t3xt.info/tutorials/keywords/