Class ExtractImages


  • public final class ExtractImages
    extends java.lang.Object
    Extracts the images from a PDF file.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.lang.String DIRECTJPEG  
      private java.lang.String filePrefix  
      private int imageCounter  
      private static java.util.List<java.lang.String> JPEG  
      private static java.lang.String PASSWORD  
      private static java.lang.String PREFIX  
      private java.util.Set<COSStream> seen  
      private boolean useDirectJPEG  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private ExtractImages()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void extract​(java.lang.String pdfFile, java.lang.String password)  
      private boolean hasMasks​(PDImage pdImage)  
      static void main​(java.lang.String[] args)
      Entry point for the application.
      private void run​(java.lang.String[] args)  
      private static void usage()
      Print the usage requirements and exit.
      private void write2file​(PDImage pdImage, java.lang.String prefix, boolean directJPEG)
      Writes the image to a file with the filename prefix + an appropriate suffix, like "Image.jpg".
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • JPEG

        private static final java.util.List<java.lang.String> JPEG
      • useDirectJPEG

        private boolean useDirectJPEG
      • filePrefix

        private java.lang.String filePrefix
      • seen

        private final java.util.Set<COSStream> seen
      • imageCounter

        private int imageCounter
    • Constructor Detail

      • ExtractImages

        private ExtractImages()
    • Method Detail

      • main

        public static void main​(java.lang.String[] args)
                         throws java.io.IOException
        Entry point for the application.
        Parameters:
        args - The command-line arguments.
        Throws:
        java.io.IOException - if there is an error reading the file or extracting the images.
      • run

        private void run​(java.lang.String[] args)
                  throws java.io.IOException
        Throws:
        java.io.IOException
      • usage

        private static void usage()
        Print the usage requirements and exit.
      • extract

        private void extract​(java.lang.String pdfFile,
                             java.lang.String password)
                      throws java.io.IOException
        Throws:
        java.io.IOException
      • write2file

        private void write2file​(PDImage pdImage,
                                java.lang.String prefix,
                                boolean directJPEG)
                         throws java.io.IOException
        Writes the image to a file with the filename prefix + an appropriate suffix, like "Image.jpg". The suffix is automatically set depending on the image compression in the PDF.
        Parameters:
        pdImage - the image.
        prefix - the filename prefix.
        directJPEG - if true, force saving JPEG/JPX streams as they are in the PDF file.
        Throws:
        java.io.IOException - When something is wrong with the corresponding file.
      • hasMasks

        private boolean hasMasks​(PDImage pdImage)
                          throws java.io.IOException
        Throws:
        java.io.IOException