Class PdfCanvasProcessor
java.lang.Object
com.itextpdf.kernel.pdf.canvas.parser.PdfCanvasProcessor
Processor for a PDF content stream.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classA handler that implements operator (Q). -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intSpecifies the filling rule which should be applied while calculating new clipping path.protected Pathstatic final Stringprotected final IEventListenerListener that will be notified of render eventsprotected booleanIndicates whether the current clipping path should be modified by intersecting it with the current path.Cache supported events in case the user'sIEventListener.getSupportedEvents()method is not very efficient -
Constructor Summary
ConstructorsConstructorDescriptionPdfCanvasProcessor(IEventListener eventListener) Creates a new PDF Content Stream Processor that will send its output to the designated render listener.PdfCanvasProcessor(IEventListener eventListener, Map<String, IContentOperator> additionalContentOperators) Creates a new PDF Content Stream Processor that will send its output to the designated render listener. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidbeginMarkedContent(PdfName tag, PdfDictionary dict) Add to the marked content stackprotected voidRemove the latest marked content from the stack.protected voideventOccurred(IEventData data, EventType type) This is a proxy to pass only those events to the event listener which are supported by it.Accessor method for theIEventListenerobject maintained in this class.protected PdfFontgetFont(PdfDictionary fontDict) Creates aPdfFontobject by a font dictionary.Gets the currentParserGraphicsStateGets theCollectioncontaining all the registered operators strings.protected PdfResourcesprotected PdfStreamgetXObjectStream(PdfName xobjectName) protected voidinvokeOperator(PdfLiteral operator, List<PdfObject> operands) Invokes an operator.protected voidpaintPath(int operation, int rule) Displays the current path.protected voidLoads all the supported graphics and text state operators in a map.protected voidvoidprocessContent(byte[] contentBytes, PdfResources resources) Processes PDF syntax.voidprocessPageContent(PdfPage page) Processes PDF syntax.registerContentOperator(String operatorString, IContentOperator operator) Registers a content operator that will be called when the specified operator string is encountered during content processing.registerXObjectDoHandler(PdfName xobjectSubType, IXObjectDoHandler handler) Registers a Do handler that will be called when Do for the provided XObject subtype is encountered during content processing.voidreset()Resets the graphics state stack, matrices and resources.
-
Field Details
-
DEFAULT_OPERATOR
- See Also:
-
eventListener
Listener that will be notified of render events -
supportedEvents
Cache supported events in case the user'sIEventListener.getSupportedEvents()method is not very efficient -
currentPath
-
isClip
protected boolean isClipIndicates whether the current clipping path should be modified by intersecting it with the current path. -
clippingRule
protected int clippingRuleSpecifies the filling rule which should be applied while calculating new clipping path.
-
-
Constructor Details
-
PdfCanvasProcessor
Creates a new PDF Content Stream Processor that will send its output to the designated render listener.- Parameters:
-
eventListener- theIEventListenerthat will receive rendering notifications
-
PdfCanvasProcessor
public PdfCanvasProcessor(IEventListener eventListener, Map<String, IContentOperator> additionalContentOperators) Creates a new PDF Content Stream Processor that will send its output to the designated render listener. Also allows registration of custom IContentOperators that can influence how (and whether or not) the PDF instructions will be parsed.- Parameters:
-
eventListener- theIEventListenerthat will receive rendering notifications -
additionalContentOperators- an optional map of customIContentOperators for rendering instructions
-
-
Method Details
-
registerXObjectDoHandler
public IXObjectDoHandler registerXObjectDoHandler(PdfName xobjectSubType, IXObjectDoHandler 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
-
registerContentOperator
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 DEFAULT_OPERATOR for a catch-all operator -
operator- the operator that will receive notification when the operator is encountered - Returns:
- the existing registered operator, if any
-
getRegisteredOperatorStrings
Gets theCollectioncontaining all the registered operators strings.- Returns:
-
Collectioncontaining all the registered operators strings.
-
reset
public void reset()Resets the graphics state stack, matrices and resources. -
getGraphicsState
Gets the currentParserGraphicsState- Returns:
-
the current
ParserGraphicsState
-
processContent
Processes PDF syntax. Note: If you re-use a givenPdfCanvasProcessor, you must callreset()- Parameters:
-
contentBytes- the bytes of a content stream -
resources- the resources of the content stream. Must not be null.
-
processPageContent
Processes PDF syntax. Note: If you re-use a givenPdfCanvasProcessor, you must callreset()- Parameters:
-
page- the page to process
-
getEventListener
Accessor method for theIEventListenerobject maintained in this class. Necessary for implementing custom ContentOperator implementations.- Returns:
- the renderListener
-
populateOperators
protected void populateOperators()Loads all the supported graphics and text state operators in a map. -
paintPath
protected void paintPath(int operation, int rule) Displays the current path.- Parameters:
-
operation- One of the possible combinations ofPathRenderInfo.STROKEandPathRenderInfo.FILLvalues orPathRenderInfo.NO_OP -
rule- EitherPdfCanvasConstants.FillingRule.NONZERO_WINDINGorPdfCanvasConstants.FillingRule.EVEN_ODDIn case it isn't applicable pass anybytevalue.
-
invokeOperator
Invokes an operator.- Parameters:
-
operator- the PDF Syntax of the operator -
operands- a list with operands
-
getXObjectStream
-
getResources
-
populateXObjectDoHandlers
protected void populateXObjectDoHandlers() -
getFont
Creates aPdfFontobject by a font dictionary. The font may have been cached in case it is an indirect object.- Parameters:
-
fontDict- thefont dictionaryto create the font from - Returns:
- the created font
-
beginMarkedContent
Add to the marked content stack- Parameters:
-
tag- the tag of the marked content -
dict- the PdfDictionary associated with the marked content
-
endMarkedContent
protected void endMarkedContent()Remove the latest marked content from the stack. Keeps track of the BMC, BDC and EMC operators. -
eventOccurred
This is a proxy to pass only those events to the event listener which are supported by it.- Parameters:
-
data- event data -
type- event type
-