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 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

      protected Map<COSObjectKey,Long> getBFCOSObjectOffsets() throws IOException
      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

      protected long bfSearchForXRef(long xrefOffset) throws 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:
      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 document
      securityHandler - 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 document
      securityHandler - security handler to be used to decrypt encrypted documents
      Returns:
      the rebuild trailer dictionary
      Throws:
      IOException - if something went wrong