Class PdfContentStreamProcessor

java.lang.Object
com.itextpdf.text.pdf.parser.PdfContentStreamProcessor

public class PdfContentStreamProcessor extends Object
Processor for a PDF content Stream.
Since:
2.1.4
  • Field Details

  • Constructor Details

    • PdfContentStreamProcessor

      public PdfContentStreamProcessor(RenderListener renderListener)
      Creates a new PDF Content Stream Processor that will send it's output to the designated render listener.
      Parameters:
      renderListener - the RenderListener that will receive rendering notifications
  • Method Details

    • populateXObjectDoHandlers

      private void populateXObjectDoHandlers()
    • registerXObjectDoHandler

      public XObjectDoHandler registerXObjectDoHandler(PdfName xobjectSubType, XObjectDoHandler handler)
      Registers a Do handler that will be called when Do for the provided XObject subtype is encountered during content processing.
      If you register a handler, it is a very good idea to pass the call on to the existing registered handler (returned by this call), otherwise you may inadvertently change the internal behavior of the processor.
      Parameters:
      xobjectSubType - the XObject subtype this handler will process, or PdfName.DEFAULT for a catch-all handler
      handler - the handler that will receive notification when the Do operator for the specified subtype is encountered
      Returns:
      the existing registered handler, if any
      Since:
      5.0.1
    • getFont

      Gets the font pointed to by the indirect reference. The font may have been cached.
      Parameters:
      ind - the indirect reference ponting to the font
      Returns:
      the font
      Since:
      5.0.6
    • getFont

      private CMapAwareDocumentFont getFont(PdfDictionary fontResource)
    • populateOperators

      private void populateOperators()
      Loads all the supported graphics and text state operators in a map.
    • registerContentOperator

      public ContentOperator registerContentOperator(String operatorString, ContentOperator operator)
      Registers a content operator that will be called when the specified operator string is encountered during content processing.
      If you register an operator, it is a very good idea to pass the call on to the existing registered operator (returned by this call), otherwise you may inadvertently change the internal behavior of the processor.
      Parameters:
      operatorString - the operator id, or DEFAULTOPERATOR for a catch-all operator
      operator - the operator that will receive notification when the operator is encountered
      Returns:
      the existing registered operator, if any
      Since:
      2.1.7
    • getRegisteredOperatorStrings

      public Collection<String> getRegisteredOperatorStrings()
      Returns:
      Collection containing all the registered operators strings
      Since:
      5.5.6
    • reset

      public void reset()
      Resets the graphics state stack, matrices and resources.
    • gs

      public GraphicsState gs()
      Returns the current graphics state.
      Returns:
      the graphics state
    • invokeOperator

      private void invokeOperator(PdfLiteral operator, ArrayList<PdfObject> operands) throws Exception
      Invokes an operator.
      Parameters:
      operator - the PDF Syntax of the operator
      operands - a list with operands
      Throws:
      Exception
    • beginMarkedContent

      private void beginMarkedContent(PdfName tag, PdfDictionary dict)
      Add to the marked content stack
      Parameters:
      tag - the tag of the marked content
      dict - the PdfDictionary associated with the marked content
      Since:
      5.0.2
    • endMarkedContent

      private void endMarkedContent()
      Remove the latest marked content from the stack. Keeps track of the BMC, BDC and EMC operators.
      Since:
      5.0.2
    • beginText

      private void beginText()
      Used to trigger beginTextBlock on the renderListener
    • endText

      private void endText()
      Used to trigger endTextBlock on the renderListener
    • displayPdfString

      private void displayPdfString(PdfString string)
      Displays text.
      Parameters:
      string - the text to display
    • displayXObject

      private void displayXObject(PdfName xobjectName) throws IOException
      Displays an XObject using the registered handler for this XObject's subtype
      Parameters:
      xobjectName - the name of the XObject to retrieve from the resource dictionary
      Throws:
      IOException
    • paintPath

      private void paintPath(int operation, int rule, boolean close)
      Displays the current path.
      Parameters:
      operation - One of the possible combinations of PathPaintingRenderInfo.STROKE and PathPaintingRenderInfo.FILL values or PathPaintingRenderInfo.NO_OP
      rule - Either PathPaintingRenderInfo.NONZERO_WINDING_RULE or PathPaintingRenderInfo.EVEN_ODD_RULE In case it isn't applicable pass any byte value.
      close - Indicates whether the path should be closed or not.
      Since:
      5.5.6
    • modifyPath

      private void modifyPath(int operation, List<Float> segmentData)
      Modifies the current path.
      Parameters:
      operation - Indicates which path-construction operation should be performed.
      segmentData - Contains x, y components of points of a new segment being added to the current path. E.g. x1 y1 x2 y2 x3 y3 etc. It's ignored for "close subpath" operarion (h).
    • clipPath

      private void clipPath(int rule)
    • applyTextAdjust

      private void applyTextAdjust(float tj)
      Adjusts the text matrix for the specified adjustment value (see TJ operator in the PDF spec for information)
      Parameters:
      tj - the text adjustment
    • processContent

      public void processContent(byte[] contentBytes, PdfDictionary resources)
      Processes PDF syntax. Note: If you re-use a given PdfContentStreamProcessor, you must call reset()
      Parameters:
      contentBytes - the bytes of a content stream
      resources - the resources that come with the content stream
    • handleInlineImage

      protected void handleInlineImage(InlineImageInfo info, PdfDictionary colorSpaceDic)
      Callback when an inline image is found. This requires special handling because inline images don't follow the standard operator syntax
      Parameters:
      info - the inline image
      colorSpaceDic - the color space for the inline immage
    • getRenderListener

      public RenderListener getRenderListener()
      Accessor method for the RenderListener object maintained in this class. Necessary for implementing custom ContentOperator implementations.
      Returns:
      the renderListener
    • getColor

      private static BaseColor getColor(PdfName colorSpace, List<PdfObject> operands)
      Gets a color based on a list of operands.
    • getColor

      private static BaseColor getColor(int nOperands, List<PdfObject> operands)
      Gets a color based on a list of operands.