Class BruteForceParser

  • All Implemented Interfaces:
    ICOSParser

    public class BruteForceParser
    extends COSParser
    Brute force parser to be used as last resort if a malformed pdf can't be read.
    • Constructor Detail

      • BruteForceParser

        public BruteForceParser​(org.apache.pdfbox.io.RandomAccessRead source,
                                COSDocument document)
                         throws java.io.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:
        java.io.IOException - if the source data could not be read
    • Method Detail

      • bfSearchTriggered

        public boolean bfSearchTriggered()
        Indicates whether the brute force search for objects was triggered.
        Returns:
        true if the search was triggered
      • getBFCOSObjectOffsets

        protected java.util.Map<COSObjectKey,​java.lang.Long> getBFCOSObjectOffsets()
                                                                                  throws java.io.IOException
        Returns all found objects of a brute force search.
        Returns:
        map containing all found objects of a brute force search
        Throws:
        java.io.IOException - if something went wrong
      • bfSearchForXRef

        protected long bfSearchForXRef​(long xrefOffset)
                                throws java.io.IOException
        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:
        java.io.IOException - if something went wrong
      • bfSearchForObjStreams

        protected void bfSearchForObjStreams​(XrefTrailerResolver trailerResolver,
                                             SecurityHandler<? extends ProtectionPolicy> securityHandler)
                                      throws java.io.IOException
        Brute force search for all objects streams of a pdf.
        Parameters:
        trailerResolver - the trailer resolver of the document
        securityHandler - security handler to be used to decrypt encrypted documents
        Throws:
        java.io.IOException - if something went wrong
      • rebuildTrailer

        protected COSDictionary rebuildTrailer​(XrefTrailerResolver trailerResolver,
                                               SecurityHandler<? extends ProtectionPolicy> securityHandler)
                                        throws java.io.IOException
        Rebuild the trailer dictionary if startxref can't be found.
        Parameters:
        trailerResolver - the trailer resolver of the document
        securityHandler - security handler to be used to decrypt encrypted documents
        Returns:
        the rebuild trailer dictionary
        Throws:
        java.io.IOException - if something went wrong