Class OCGParser

java.lang.Object
com.itextpdf.text.pdf.ocg.OCGParser

public class OCGParser extends Object
A helper class for OCGRemover.
  • Field Details

    • DEFAULTOPERATOR

      public static final String DEFAULTOPERATOR
      Constant used for the default operator.
      See Also:
    • operators

      protected static final Map<String,OCGParser.PdfOperator> operators
      A map with all supported operators operators (PDF syntax).
    • baos

      protected ByteArrayOutputStream baos
      The OutputStream of this worker object.
    • mc_balance

      protected int mc_balance
      Keeps track of BMC/EMC balance.
    • xobj

      protected Set<PdfName> xobj
      The names of XObjects that shouldn't be shown.
    • ocgs

      protected Set<String> ocgs
      The OCGs that need to be removed.
    • properties

      protected PdfDictionary properties
      The OCG properties.
  • Constructor Details

    • OCGParser

      public OCGParser(Set<String> ocgs)
      Creates an instance of the OCGParser.
      Parameters:
      ocgs - a set of String values with the names of the OCGs that need to be removed.
  • Method Details

    • parse

      public void parse(PRStream stream, PdfDictionary resources) throws IOException
      Parses a stream object and removes OCGs.
      Parameters:
      stream - a stream object
      resources - the resources dictionary of that object (containing info about the OCGs)
      Throws:
      IOException
    • processOperator

      protected static void processOperator(OCGParser parser, PdfLiteral operator, List<PdfObject> operands) throws Exception
      Processes an operator.
      Parameters:
      parser - the parser that needs to process the operator
      operator - the operator
      operands - its operands
      Throws:
      Exception
    • populateOperators

      protected static void populateOperators()
      Populates the operators variable.
    • isVisible

      protected boolean isVisible(List<PdfObject> operands)
      Checks operands to find out if the corresponding operator needs to be present or not.
      Parameters:
      operands - a list of operands
      Returns:
      true if the operators needs to be present.
    • isToRemoved

      protected boolean isToRemoved()
      Checks if the parser is currently parsing content that needs to be ignored.
      Returns:
      true if the content needs to be ignored
    • checkMarkedContentStart

      protected void checkMarkedContentStart(PdfName ocref)
      Keeps track of the MarkedContent state.
      Parameters:
      ocref - a reference to an OCG dictionary
    • checkMarkedContentEnd

      protected void checkMarkedContentEnd()
      Keeps track of the MarkedContent state.
    • process

      protected void process(PdfLiteral operator, List<PdfObject> operands, boolean removable) throws IOException
      Processes an operator
      Parameters:
      operator - the operator
      operands - its operands
      removable - is the operator eligable for removal?
      Throws:
      IOException
    • printsp

      protected void printsp(PdfObject o) throws IOException
      Writes a PDF object to the OutputStream, followed by a space character.
      Parameters:
      o -
      Throws:
      IOException
    • println

      protected void println(PdfObject o) throws IOException
      Writes a PDF object to the OutputStream, followed by a newline character.
      Parameters:
      o -
      Throws:
      IOException