Class PreflightParser
- java.lang.Object
-
- org.apache.pdfbox.pdfparser.BaseParser
-
- org.apache.pdfbox.pdfparser.COSParser
-
- org.apache.pdfbox.pdfparser.PDFParser
-
- org.apache.pdfbox.preflight.parser.PreflightParser
-
- All Implemented Interfaces:
org.apache.pdfbox.cos.ICOSParser
public class PreflightParser extends org.apache.pdfbox.pdfparser.PDFParser
-
-
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.PDDocumentcreateDocument()protected voidinitialParse()protected intlastIndexOf(char[] pattern, byte[] buf, int endOff)org.apache.pdfbox.pdmodel.PDDocumentparse()org.apache.pdfbox.pdmodel.PDDocumentparse(Format format)Parse the given file and check if it is a confirming file according to the given format.org.apache.pdfbox.pdmodel.PDDocumentparse(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.COSArrayparseCOSArray()protected org.apache.pdfbox.cos.COSNameparseCOSName()protected org.apache.pdfbox.cos.COSStreamparseCOSStream(org.apache.pdfbox.cos.COSDictionary dic)Wraps theCOSParser.parseCOSStream(org.apache.pdfbox.cos.COSDictionary)to check rules on 'stream' and 'endstream' keywords.protected org.apache.pdfbox.cos.COSStringparseCOSString()Check that the hexa string contains only an even number of Hexadecimal characters.protected org.apache.pdfbox.cos.COSBaseparseDirObject()CallBaseParser.parseDirObject()check limit range for Float, Integer and number of Dictionary entries.protected org.apache.pdfbox.cos.COSBaseparseObjectDynamically(org.apache.pdfbox.cos.COSObjectKey objKey, boolean requireExistingNotCompressedObj)protected booleanparseXrefTable(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 onprotected booleanresetTrailerResolver()static ValidationResultvalidate(java.io.File file)Load and validate the given file.-
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
-
-
-
-
Constructor Detail
-
PreflightParser
public PreflightParser(java.io.File file) throws java.io.IOExceptionConstructor.- Parameters:
file-- Throws:
java.io.IOException- if there is a reading error.
-
PreflightParser
public PreflightParser(org.apache.pdfbox.io.RandomAccessRead rar) throws java.io.IOExceptionConstructor.- Parameters:
rar- input source- Throws:
java.io.IOException- if there is a reading error.
-
PreflightParser
public PreflightParser(java.lang.String filename) throws java.io.IOExceptionConstructor.- 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:
parsein classorg.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 (defaultFormat.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 (defaultFormat.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:
createDocumentin classorg.apache.pdfbox.pdfparser.PDFParser- Throws:
java.io.IOException
-
initialParse
protected void initialParse() throws java.io.IOException- Overrides:
initialParsein classorg.apache.pdfbox.pdfparser.PDFParser- Throws:
java.io.IOException
-
resetTrailerResolver
protected boolean resetTrailerResolver()
- Overrides:
resetTrailerResolverin classorg.apache.pdfbox.pdfparser.COSParser
-
parseXrefTable
protected boolean parseXrefTable(long startByteOffset) throws java.io.IOExceptionSame 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:
parseXrefTablein classorg.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.IOExceptionWraps theCOSParser.parseCOSStream(org.apache.pdfbox.cos.COSDictionary)to check rules on 'stream' and 'endstream' keywords.checkStreamKeyWord()andcheckEndstreamKeyWord(org.apache.pdfbox.cos.COSDictionary, long)- Overrides:
parseCOSStreamin classorg.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:
parseCOSArrayin classorg.apache.pdfbox.pdfparser.BaseParser- Throws:
java.io.IOException
-
parseCOSName
protected org.apache.pdfbox.cos.COSName parseCOSName() throws java.io.IOException- Overrides:
parseCOSNamein classorg.apache.pdfbox.pdfparser.BaseParser- Throws:
java.io.IOException
-
parseCOSString
protected org.apache.pdfbox.cos.COSString parseCOSString() throws java.io.IOExceptionCheck 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 callBaseParser.parseCOSString()- Overrides:
parseCOSStringin classorg.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.IOExceptionCallBaseParser.parseDirObject()check limit range for Float, Integer and number of Dictionary entries.- Overrides:
parseDirObjectin classorg.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:
parseObjectDynamicallyin classorg.apache.pdfbox.pdfparser.COSParser- Throws:
java.io.IOException
-
lastIndexOf
protected int lastIndexOf(char[] pattern, byte[] buf, int endOff)- Overrides:
lastIndexOfin classorg.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
-
-