Package org.apache.pdfbox.pdfparser
Class BruteForceParser
java.lang.Object
org.apache.pdfbox.pdfparser.BaseParser
org.apache.pdfbox.pdfparser.COSParser
org.apache.pdfbox.pdfparser.BruteForceParser
- All Implemented Interfaces:
ICOSParser
Brute force parser to be used as last resort if a malformed pdf can't be read.
-
Field Summary
Fields inherited from class org.apache.pdfbox.pdfparser.COSParser
fileLen, initialParseDone, securityHandler, SYSPROP_EOFLOOKUPRANGE, xrefTrailerResolverFields 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
ConstructorsConstructorDescriptionBruteForceParser(org.apache.pdfbox.io.RandomAccessRead source, COSDocument document) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidbfSearchForObjStreams(XrefTrailerResolver trailerResolver, SecurityHandler<? extends ProtectionPolicy> securityHandler) Brute force search for all objects streams of a pdf.protected longbfSearchForXRef(long xrefOffset) Search for the offset of the given xref table/stream among those found by a brute force search.booleanIndicates whether the brute force search for objects was triggered.protected Map<COSObjectKey, Long> Returns all found objects of a brute force search.protected COSDictionaryrebuildTrailer(XrefTrailerResolver trailerResolver, SecurityHandler<? extends ProtectionPolicy> securityHandler) Rebuild the trailer dictionary if startxref can't be found.Methods inherited from class org.apache.pdfbox.pdfparser.COSParser
checkPages, createRandomAccessReadView, dereferenceCOSObject, getAccessPermission, getEncryption, isLenient, isString, lastIndexOf, parseCOSStream, parseFDFHeader, parseObjectDynamically, parseObjectStreamObject, parsePDFHeader, parseXrefTable, prepareDecryption, resetTrailerResolver, retrieveTrailer, setEOFLookupRange, setLenientMethods inherited from class org.apache.pdfbox.pdfparser.BaseParser
getObjectKey, isClosing, isClosing, isDigit, isDigit, isEndOfName, isEOF, isEOL, isEOL, isSpace, isSpace, isWhitespace, isWhitespace, parseCOSArray, parseCOSDictionary, parseCOSName, parseCOSString, parseDirObject, readExpectedChar, readExpectedString, readGenerationNumber, readInt, readLine, readLong, readObjectNumber, readString, readString, readStringNumber, skipLinebreak, skipSpaces, skipWhiteSpaces
-
Constructor Details
-
BruteForceParser
public BruteForceParser(org.apache.pdfbox.io.RandomAccessRead source, COSDocument document) throws IOException Constructor. Triggers a brute force search for all objects of the document.- Parameters:
source- input representing the pdf.document- the corresponding COS document- Throws:
IOException- if the source data could not be read
-
-
Method Details
-
bfSearchTriggered
public boolean bfSearchTriggered()Indicates whether the brute force search for objects was triggered.- Returns:
- true if the search was triggered
-
getBFCOSObjectOffsets
Returns all found objects of a brute force search.- Returns:
- map containing all found objects of a brute force search
- Throws:
IOException- if something went wrong
-
bfSearchForXRef
Search for the offset of the given xref table/stream among those found by a brute force search.- Parameters:
xrefOffset- the given offset to be searched for- Returns:
- the offset of the xref entry
- Throws:
IOException- if something went wrong
-
bfSearchForObjStreams
protected void bfSearchForObjStreams(XrefTrailerResolver trailerResolver, SecurityHandler<? extends ProtectionPolicy> securityHandler) throws IOException Brute force search for all objects streams of a pdf.- Parameters:
trailerResolver- the trailer resolver of the documentsecurityHandler- security handler to be used to decrypt encrypted documents- Throws:
IOException- if something went wrong
-
rebuildTrailer
protected COSDictionary rebuildTrailer(XrefTrailerResolver trailerResolver, SecurityHandler<? extends ProtectionPolicy> securityHandler) throws IOException Rebuild the trailer dictionary if startxref can't be found.- Parameters:
trailerResolver- the trailer resolver of the documentsecurityHandler- security handler to be used to decrypt encrypted documents- Returns:
- the rebuild trailer dictionary
- Throws:
IOException- if something went wrong
-