Class PreflightParser

  • All Implemented Interfaces:
    org.apache.pdfbox.cos.ICOSParser

    public class PreflightParser
    extends org.apache.pdfbox.pdfparser.PDFParser
    • Field Summary

      • Fields inherited from class org.apache.pdfbox.pdfparser.COSParser

        EOF_MARKER, fileLen, initialParseDone, OBJ_MARKER, securityHandler, SYSPROP_EOFLOOKUPRANGE, xrefTrailerResolver
      • Fields inherited from class org.apache.pdfbox.pdfparser.BaseParser

        A, ASCII_CR, ASCII_LF, B, D, DEF, document, E, ENDOBJ_STRING, ENDSTREAM_STRING, J, M, N, O, R, S, source, STREAM_STRING, T
    • Constructor Summary

      Constructors 
      Constructor Description
      PreflightParser​(java.io.File file)
      Constructor.
      PreflightParser​(java.lang.String filename)
      Constructor.
      PreflightParser​(org.apache.pdfbox.io.RandomAccessRead rar)
      Constructor.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected org.apache.pdfbox.pdmodel.PDDocument createDocument()  
      protected void initialParse()  
      protected int lastIndexOf​(char[] pattern, byte[] buf, int endOff)  
      org.apache.pdfbox.pdmodel.PDDocument parse()  
      org.apache.pdfbox.pdmodel.PDDocument parse​(Format format)
      Parse the given file and check if it is a confirming file according to the given format.
      org.apache.pdfbox.pdmodel.PDDocument parse​(Format format, PreflightConfiguration config)
      Parse the given file and check if it is a confirming file according to the given format.
      protected org.apache.pdfbox.cos.COSArray parseCOSArray()  
      protected org.apache.pdfbox.cos.COSName parseCOSName()  
      protected org.apache.pdfbox.cos.COSStream parseCOSStream​(org.apache.pdfbox.cos.COSDictionary dic)
      Wraps the COSParser.parseCOSStream(org.apache.pdfbox.cos.COSDictionary) to check rules on 'stream' and 'endstream' keywords.
      protected org.apache.pdfbox.cos.COSString parseCOSString()
      Check that the hexa string contains only an even number of Hexadecimal characters.
      protected org.apache.pdfbox.cos.COSBase parseDirObject()
      Call BaseParser.parseDirObject() check limit range for Float, Integer and number of Dictionary entries.
      protected org.apache.pdfbox.cos.COSBase parseObjectDynamically​(org.apache.pdfbox.cos.COSObjectKey objKey, boolean requireExistingNotCompressedObj)  
      protected boolean parseXrefTable​(long startByteOffset)
      Same method than the COSParser.parseXrefTable(long) with additional controls : - EOL mandatory after the 'xref' keyword - Cross reference subsection header uses single white space as separator - and so on
      protected boolean resetTrailerResolver()  
      static ValidationResult validate​(java.io.File file)
      Load and validate the given file.
      • Methods inherited from class org.apache.pdfbox.pdfparser.PDFParser

        load, load, parse
      • Methods inherited from class org.apache.pdfbox.pdfparser.COSParser

        checkPages, createRandomAccessReadView, dereferenceCOSObject, getAccessPermission, getEncryption, isLenient, isString, parseFDFHeader, parseObjectStreamObject, parsePDFHeader, prepareDecryption, retrieveTrailer, setEOFLookupRange, setLenient
      • Methods inherited from class org.apache.pdfbox.pdfparser.BaseParser

        getObjectKey, isClosing, isClosing, isDigit, isDigit, isEndOfName, isEOF, isEOL, isEOL, isSpace, isSpace, isWhitespace, isWhitespace, parseCOSDictionary, readExpectedChar, readExpectedString, readGenerationNumber, readInt, readLine, readLong, readObjectNumber, readString, readString, readStringNumber, skipLinebreak, skipSpaces, skipWhiteSpaces
      • Methods inherited from class java.lang.Object

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

      • PreflightParser

        public PreflightParser​(java.io.File file)
                        throws java.io.IOException
        Constructor.
        Parameters:
        file -
        Throws:
        java.io.IOException - if there is a reading error.
      • PreflightParser

        public PreflightParser​(org.apache.pdfbox.io.RandomAccessRead rar)
                        throws java.io.IOException
        Constructor.
        Parameters:
        rar - input source
        Throws:
        java.io.IOException - if there is a reading error.
      • PreflightParser

        public PreflightParser​(java.lang.String filename)
                        throws java.io.IOException
        Constructor.
        Parameters:
        filename -
        Throws:
        java.io.IOException - if there is a reading error.
    • Method Detail

      • parse

        public org.apache.pdfbox.pdmodel.PDDocument parse()
                                                   throws java.io.IOException
        Overrides:
        parse in class org.apache.pdfbox.pdfparser.PDFParser
        Throws:
        java.io.IOException
      • parse

        public org.apache.pdfbox.pdmodel.PDDocument parse​(Format format)
                                                   throws java.io.IOException
        Parse the given file and check if it is a confirming file according to the given format.
        Parameters:
        format - format that the document should follow (default Format.PDF_A1B)
        Returns:
        the parsed document.
        Throws:
        java.io.IOException
      • parse

        public org.apache.pdfbox.pdmodel.PDDocument parse​(Format format,
                                                          PreflightConfiguration config)
                                                   throws java.io.IOException
        Parse the given file and check if it is a confirming file according to the given format.
        Parameters:
        format - format that the document should follow (default Format.PDF_A1B)
        config - Configuration bean that will be used by the PreflightDocument. If null the format is used to determine the default configuration.
        Returns:
        the parsed document.
        Throws:
        java.io.IOException
      • createDocument

        protected org.apache.pdfbox.pdmodel.PDDocument createDocument()
                                                               throws java.io.IOException
        Overrides:
        createDocument in class org.apache.pdfbox.pdfparser.PDFParser
        Throws:
        java.io.IOException
      • initialParse

        protected void initialParse()
                             throws java.io.IOException
        Overrides:
        initialParse in class org.apache.pdfbox.pdfparser.PDFParser
        Throws:
        java.io.IOException
      • resetTrailerResolver

        protected boolean resetTrailerResolver()
        Overrides:
        resetTrailerResolver in class org.apache.pdfbox.pdfparser.COSParser
      • parseXrefTable

        protected boolean parseXrefTable​(long startByteOffset)
                                  throws java.io.IOException
        Same method than the COSParser.parseXrefTable(long) with additional controls : - EOL mandatory after the 'xref' keyword - Cross reference subsection header uses single white space as separator - and so on
        Overrides:
        parseXrefTable in class org.apache.pdfbox.pdfparser.COSParser
        Parameters:
        startByteOffset - the offset to start at
        Returns:
        false on parsing error
        Throws:
        java.io.IOException - If an IO error occurs.
      • parseCOSStream

        protected org.apache.pdfbox.cos.COSStream parseCOSStream​(org.apache.pdfbox.cos.COSDictionary dic)
                                                          throws java.io.IOException
        Wraps the COSParser.parseCOSStream(org.apache.pdfbox.cos.COSDictionary) to check rules on 'stream' and 'endstream' keywords. checkStreamKeyWord() and checkEndstreamKeyWord(org.apache.pdfbox.cos.COSDictionary, long)
        Overrides:
        parseCOSStream in class org.apache.pdfbox.pdfparser.COSParser
        Parameters:
        dic - dictionary that goes with this stream.
        Returns:
        parsed pdf stream.
        Throws:
        java.io.IOException - if an error occurred reading the stream, like problems with reading length attribute, stream does not end with 'endstream' after data read, stream too short etc.
      • parseCOSArray

        protected org.apache.pdfbox.cos.COSArray parseCOSArray()
                                                        throws java.io.IOException
        Overrides:
        parseCOSArray in class org.apache.pdfbox.pdfparser.BaseParser
        Throws:
        java.io.IOException
      • parseCOSName

        protected org.apache.pdfbox.cos.COSName parseCOSName()
                                                      throws java.io.IOException
        Overrides:
        parseCOSName in class org.apache.pdfbox.pdfparser.BaseParser
        Throws:
        java.io.IOException
      • parseCOSString

        protected org.apache.pdfbox.cos.COSString parseCOSString()
                                                          throws java.io.IOException
        Check that the hexa string contains only an even number of Hexadecimal characters. Once it is done, reset the offset at the beginning of the string and call BaseParser.parseCOSString()
        Overrides:
        parseCOSString in class org.apache.pdfbox.pdfparser.BaseParser
        Returns:
        The parsed PDF string.
        Throws:
        java.io.IOException - If there is an error reading from the stream.
      • parseDirObject

        protected org.apache.pdfbox.cos.COSBase parseDirObject()
                                                        throws java.io.IOException
        Call BaseParser.parseDirObject() check limit range for Float, Integer and number of Dictionary entries.
        Overrides:
        parseDirObject in class org.apache.pdfbox.pdfparser.BaseParser
        Returns:
        The parsed object.
        Throws:
        java.io.IOException - if there is an error during parsing.
      • parseObjectDynamically

        protected org.apache.pdfbox.cos.COSBase parseObjectDynamically​(org.apache.pdfbox.cos.COSObjectKey objKey,
                                                                       boolean requireExistingNotCompressedObj)
                                                                throws java.io.IOException
        Overrides:
        parseObjectDynamically in class org.apache.pdfbox.pdfparser.COSParser
        Throws:
        java.io.IOException
      • lastIndexOf

        protected int lastIndexOf​(char[] pattern,
                                  byte[] buf,
                                  int endOff)
        Overrides:
        lastIndexOf in class org.apache.pdfbox.pdfparser.COSParser
      • validate

        public static ValidationResult validate​(java.io.File file)
                                         throws java.io.IOException
        Load and validate the given file. Returns the validation result and closes the read pdf.
        Parameters:
        file - thew file to be read and validated
        Returns:
        the validation result
        Throws:
        java.io.IOException - in case of a file reading or parsing error