Class ExtractEmbeddedFiles

java.lang.Object
org.jpedal.examples.acroform.ExtractEmbeddedFiles

public class ExtractEmbeddedFiles extends Object

File Extraction from PDF files


This class provides a simple Java API to extract embedded files and file attachments from a PDF file and also a static convenience method if you just want to dump all files from a PDF file or directory containing PDF files. All files are extracted to a folder at the given output location with a name matching the pdf filename

Example 1 - access API methods


 ExtractEmbeddedFiles extract=new ExtractEmbeddedFiles("C:/pdfs/mypdf.pdf");
 //extract.setPassword("password");
 if (extract.openPDFFile()) {
     if (extract.containsEmbeddedFiles()) {
         extract.extractEmbeddedFiles("C:/output/");
     }
     if (extract.containsFilesAttachments()) {
         extract.extractFileAttachments("C:/output");
     }
 }
 extract.closePDFfile();
 

Example 2 - convenience static method

Extract all embedded files and file attachments from a pdf


 ExtractEmbeddedFiles.extractAllFilesFromPdf("C:/pdfs/mypdf.pdf", "C:/output");
 

Example 3 - Access directly from the Jar

ExtractEmbeddedFiles can run from jar directly using the command and will extract all embedded files and file attachments from a PDF file or directory to a defined output directory:

java -cp libraries_needed org/jpedal/examples/acroform/ExtractEmbeddedFiles inputValues

Where inputValues is 3 values:
  • First value: The PDF filename (including the path if needed) or a directory containing PDF files. If it contains spaces it must be enclosed by double quotes (ie "C:/Path with spaces/").
  • Second value: The location to write out extracted files from the PDF file or files. If it contains spaces it must be enclosed by double quotes (ie "C:/Path with spaces/").

  • Constructor Details

    • ExtractEmbeddedFiles

      public ExtractEmbeddedFiles(String fileName)
    • ExtractEmbeddedFiles

      public ExtractEmbeddedFiles(byte[] byteArray)
  • Method Details

    • main

      public static void main(String[] args)
    • setPassword

      public void setPassword(String password)
      Parameters:
      password - the USER or OWNER password for the PDF file
    • showEmbeddedFilesDetails

      public void showEmbeddedFilesDetails()
    • showFileAttachmentDetails

      public void showFileAttachmentDetails()