Extracting objects from a PDF

This is a code example of iText PDF, discover more.

8th November 2015
admin-marketing

Switch code for this example

ExtractStreams.java
  1. /**
  2.  * Example written by Bruno Lowagie in answer to the following question:
  3.  * http://stackoverflow.com/questions/30286601/extracting-an-embedded-object-from-a-pdf
  4.  */
  5. package sandbox.parse;
  6.  
  7. import com.itextpdf.text.exceptions.UnsupportedPdfException;
  8. import com.itextpdf.text.pdf.PRStream;
  9. import com.itextpdf.text.pdf.PdfObject;
  10. import com.itextpdf.text.pdf.PdfReader;
  11.  
  12. import java.io.File;
  13. import java.io.FileOutputStream;
  14. import java.io.IOException;
  15.  
  16. /**
  17.  * @author iText
  18.  */
  19. public class ExtractStreams {
  20.     public static final String SRC = "resources/pdfs/image.pdf";
  21.     public static final String DEST = "results/parse/stream%s";
  22.    
  23.     public static void main(String[] args) throws IOException {
  24.         File file = new File(DEST);
  25.         file.getParentFile().mkdirs();
  26.         new ExtractStreams().parse(SRC, DEST);
  27.     }
  28.    
  29.     public void parse(String src, String dest) throws IOException {
  30.         PdfReader reader = new PdfReader(src);
  31.         PdfObject obj;
  32.         for (int i = 1; i

Resources

Contact

Still have questions? 

We're happy to answer your questions. Reach out to us and we'll get back to you shortly.

Contact us
Stay updated

Join 11,000+ subscribers and become an iText PDF expert by staying up to date with our new products, updates, tips, technical solutions and happenings.

Subscribe Now