com.itextpdf.text.pdf.parser
Class PdfContentStreamProcessor

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

public class PdfContentStreamProcessor
extends Object

Processor for a PDF content Stream.

Since:
2.1.4

Nested Class Summary
private static class PdfContentStreamProcessor.BeginText
          A content operator implementation (BT).
private static class PdfContentStreamProcessor.Do
          A content operator implementation (Do).
private static class PdfContentStreamProcessor.EndText
          A content operator implementation (ET).
private static class PdfContentStreamProcessor.FormXObjectDoHandler
          An XObject subtype handler for FORM
private static class PdfContentStreamProcessor.IgnoreOperatorContentOperator
          A content operator implementation (TJ).
private static class PdfContentStreamProcessor.IgnoreXObjectDoHandler
          An XObject subtype handler that does nothing
private static class PdfContentStreamProcessor.ImageXObjectDoHandler
          An XObject subtype handler for IMAGE
private static class PdfContentStreamProcessor.ModifyCurrentTransformationMatrix
          A content operator implementation (cm).
private static class PdfContentStreamProcessor.MoveNextLineAndShowText
          A content operator implementation (').
private static class PdfContentStreamProcessor.MoveNextLineAndShowTextWithSpacing
          A content operator implementation (").
private static class PdfContentStreamProcessor.PopGraphicsState
          A content operator implementation (Q).
private static class PdfContentStreamProcessor.ProcessGraphicsStateResource
          A content operator implementation (gs).
private static class PdfContentStreamProcessor.PushGraphicsState
          A content operator implementation (q).
private static class PdfContentStreamProcessor.ResourceDictionary
          A resource dictionary that allows stack-like behavior to support resource dictionary inheritance
private static class PdfContentStreamProcessor.SetTextCharacterSpacing
          A content operator implementation (Tc).
private static class PdfContentStreamProcessor.SetTextFont
          A content operator implementation (Tf).
private static class PdfContentStreamProcessor.SetTextHorizontalScaling
          A content operator implementation (Tz).
private static class PdfContentStreamProcessor.SetTextLeading
          A content operator implementation (TL).
private static class PdfContentStreamProcessor.SetTextRenderMode
          A content operator implementation (Tr).
private static class PdfContentStreamProcessor.SetTextRise
          A content operator implementation (Ts).
private static class PdfContentStreamProcessor.SetTextWordSpacing
          A content operator implementation (Tw).
private static class PdfContentStreamProcessor.ShowText
          A content operator implementation (Tj).
private static class PdfContentStreamProcessor.ShowTextArray
          A content operator implementation (TJ).
private static class PdfContentStreamProcessor.TextMoveNextLine
          A content operator implementation (T*).
private static class PdfContentStreamProcessor.TextMoveStartNextLine
          A content operator implementation (Td).
private static class PdfContentStreamProcessor.TextMoveStartNextLineWithLeading
          A content operator implementation (TD).
private static class PdfContentStreamProcessor.TextSetTextMatrix
          A content operator implementation (Tm).
 
Field Summary
static String DEFAULTOPERATOR
          Default operator
private  Stack<GraphicsState> gsStack
          Stack keeping track of the graphics state.
private  Map<String,ContentOperator> operators
          A map with all supported operators operators (PDF syntax).
private  RenderListener renderListener
          Listener that will be notified of render events
private  PdfContentStreamProcessor.ResourceDictionary resources
          Resources for the content stream.
private  Matrix textLineMatrix
          Text line matrix.
private  Matrix textMatrix
          Text matrix.
private  Map<PdfName,XObjectDoHandler> xobjectDoHandlers
          A map with all supported XObject handlers
 
Constructor Summary
PdfContentStreamProcessor(RenderListener renderListener)
          Creates a new PDF Content Stream Processor that will send it's output to the designated render listener.
 
Method Summary
private  void applyTextAdjust(float tj)
          Adjusts the text matrix for the specified adjustment value (see TJ operator in the PDF spec for information)
private  void beginText()
          Used to trigger beginTextBlock on the renderListener
private  String decode(PdfString in)
          Decodes a PdfString (which will contain glyph ids encoded in the font's encoding) based on the active font, and determine the unicode equivalent
private  void displayPdfString(PdfString string)
          Displays text.
private  void displayXObject(PdfName xobjectName)
          Displays an XObject using the registered handler for this XObject's subtype
private  void endText()
          Used to trigger endTextBlock on the renderListener
private  GraphicsState gs()
          Returns the current graphics state.
private  void invokeOperator(PdfLiteral operator, ArrayList<PdfObject> operands)
          Invokes an operator.
private  void populateOperators()
          Loads all the supported graphics and text state operators in a map.
private  void populateXObjectDoHandlers()
           
 void processContent(byte[] contentBytes, PdfDictionary resources)
          Processes PDF syntax
 ContentOperator registerContentOperator(String operatorString, ContentOperator operator)
          Registers a content operator that will be called when the specified operator string is encountered during content processing.
 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.
 void reset()
          Resets the graphics state stack, matrices and resources.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULTOPERATOR

public static final String DEFAULTOPERATOR
Default operator

Since:
5.0.1
See Also:
Constant Field Values

operators

private final Map<String,ContentOperator> operators
A map with all supported operators operators (PDF syntax).


resources

private PdfContentStreamProcessor.ResourceDictionary resources
Resources for the content stream.


gsStack

private Stack<GraphicsState> gsStack
Stack keeping track of the graphics state.


textMatrix

private Matrix textMatrix
Text matrix.


textLineMatrix

private Matrix textLineMatrix
Text line matrix.


renderListener

private final RenderListener renderListener
Listener that will be notified of render events


xobjectDoHandlers

private final Map<PdfName,XObjectDoHandler> xobjectDoHandlers
A map with all supported XObject handlers

Constructor Detail

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 Detail

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

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

reset

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


gs

private 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

decode

private String decode(PdfString in)
Decodes a PdfString (which will contain glyph ids encoded in the font's encoding) based on the active font, and determine the unicode equivalent

Parameters:
in - the String that needs to be encoded
Returns:
the encoded String
Since:
2.1.7

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

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

Parameters:
contentBytes - the bytes of a content stream
resources - the resources that come with the content stream

Hosted by Hostbasket