Package com.itextpdf.text.pdf.mc
Class MCParser
java.lang.Object
com.itextpdf.text.pdf.mc.MCParser
This class will parse page content streams and add Do operators
in a marked-content sequence for every field that needs to be
flattened.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
Class that knows how to process marked content operators.private static class
Class that knows how to process the BT operator.private static class
Class that processes content by just printing the operator and its operands.private static class
Class that knows how to process Do operators.private static class
Class that knows how to the ET operators.static interface
PDF Operator interface.private static class
Class that knows how to the text state operators that result in a newline.private static class
Class that knows how to the ET operators.private static class
Class that knows how to the text state operators. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected PdfArray
the annotations of the page that is being processed.protected ByteArrayOutputStream
The contents of the new content stream of the page.protected boolean
Did we postpone writing a BT operator?static final String
Constant used for the default operator.protected boolean
Did we postpone writing a BT operator?protected boolean
Are we inside a BT/ET sequence?protected StructureItems
The list with structure items.protected static final Logger
The Logger instanceprotected Map<String,
MCParser.PdfOperator> A map with all supported operators operators (PDF syntax).protected PdfDictionary
The page dictionaryprotected PdfIndirectReference
The reference to the page dictionaryprotected static final RandomAccessSourceFactory
Factory that will help us build a RandomAccessSource.protected PdfNumber
the StructParents of the page that is being processed.protected StringBuffer
A buffer containing text state.static final PdfLiteral
A new line operatorprotected PdfDictionary
the XObject dictionary of the page that is being processed. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
checkBT()
Checks if a BT operator is waiting to be added.protected void
Converts an annotation structure item to a Form XObject annotation.protected void
dealWithMcid
(PdfNumber mcid) When an MCID is encountered, the parser will check the list structure items and turn an annotation into an XObject if necessary.protected void
dealWithXObj
(PdfName xobj) When an XObject with a StructParent is encountered, we want to remove it from the stack.void
parse
(PdfDictionary page, PdfIndirectReference pageref) Parses the content of a page, inserting the normal (/N) appearances (/AP) of annotations into the content stream as Form XObjects.protected void
Populates the operators variable.protected void
Writes a PDF object to the OutputStream, followed by a newline character.protected void
printOperator
(PdfLiteral operator, List<PdfObject> operands) Adds an operator and its operands (if any) to baos.protected void
Writes a PDF object to the OutputStream, followed by a space character.protected void
printTextOperator
(PdfLiteral operator, List<PdfObject> operands) Adds an operator and its operands (if any) to baos, keeping track of the text state.protected void
processOperator
(PdfLiteral operator, List<PdfObject> operands) Processes an operator, for instance: write the operator and its operands to baos.protected void
setInText
(boolean inText) Informs the parser that we're inside or outside a text object.
-
Field Details
-
LOGGER
The Logger instance -
RASFACTORY
Factory that will help us build a RandomAccessSource. -
DEFAULTOPERATOR
Constant used for the default operator.- See Also:
-
TSTAR
A new line operator -
operators
A map with all supported operators operators (PDF syntax). -
items
The list with structure items. -
baos
The contents of the new content stream of the page. -
page
The page dictionary -
pageref
The reference to the page dictionary -
annots
the annotations of the page that is being processed. -
structParents
the StructParents of the page that is being processed. -
xobjects
the XObject dictionary of the page that is being processed. -
btWrite
protected boolean btWriteDid we postpone writing a BT operator? -
etExtra
protected boolean etExtraDid we postpone writing a BT operator? -
inText
protected boolean inTextAre we inside a BT/ET sequence? -
text
A buffer containing text state.
-
-
Constructor Details
-
MCParser
Creates an MCParser object.- Parameters:
items
- a list of StructureItem objects
-
-
Method Details
-
populateOperators
protected void populateOperators()Populates the operators variable. -
parse
public void parse(PdfDictionary page, PdfIndirectReference pageref) throws IOException, DocumentException Parses the content of a page, inserting the normal (/N) appearances (/AP) of annotations into the content stream as Form XObjects.- Parameters:
page
- a page dictionarypageref
- the reference to the page dictionaryfinalPage
- indicates whether the page being processed is the final page in the document- Throws:
IOException
DocumentException
-
dealWithXObj
When an XObject with a StructParent is encountered, we want to remove it from the stack.- Parameters:
xobj
- the name of an XObject
-
dealWithMcid
When an MCID is encountered, the parser will check the list structure items and turn an annotation into an XObject if necessary.- Parameters:
mcid
- the MCID that was encountered in the content stream- Throws:
IOException
DocumentException
-
convertToXObject
Converts an annotation structure item to a Form XObject annotation.- Parameters:
item
- the structure item- Throws:
IOException
DocumentException
-
processOperator
protected void processOperator(PdfLiteral operator, List<PdfObject> operands) throws IOException, DocumentException Processes an operator, for instance: write the operator and its operands to baos.- Parameters:
operator
- the operatoroperands
- the operator's operands- Throws:
IOException
DocumentException
-
printOperator
Adds an operator and its operands (if any) to baos.- Parameters:
operator
- the operatoroperands
- its operands- Throws:
IOException
-
printTextOperator
Adds an operator and its operands (if any) to baos, keeping track of the text state.- Parameters:
operator
- the operatoroperands
- its operands- Throws:
IOException
-
printsp
Writes a PDF object to the OutputStream, followed by a space character.- Parameters:
o
- a PdfObject- Throws:
IOException
-
println
Writes a PDF object to the OutputStream, followed by a newline character.- Parameters:
o
- a PdfObject- Throws:
IOException
-
checkBT
Checks if a BT operator is waiting to be added.- Throws:
IOException
-
setInText
protected void setInText(boolean inText) Informs the parser that we're inside or outside a text object. Also sets a parameter indicating that BT needs to be written.- Parameters:
inText
- true if we're inside.
-