Package com.itextpdf.text.pdf.ocg
Class OCGParser
- java.lang.Object
-
- com.itextpdf.text.pdf.ocg.OCGParser
-
public class OCGParser extends java.lang.Object
A helper class for OCGRemover.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
OCGParser.CopyContentOperator
Class that processes unknown content.private static class
OCGParser.GraphicsOperator
Class that knows how to process graphics state operators.private static class
OCGParser.InlineImageOperator
Class that knows how to process inline image operators.private static class
OCGParser.MarkedContentOperator
Class that knows how to process marked content operators.private static class
OCGParser.PathConstructionOrPaintingOperator
Class that knows how to process path construction, path painting and path clipping operators.static interface
OCGParser.PdfOperator
PDF Operator interface.private static class
OCGParser.TextOperator
Class that knows how to process text state operators.private static class
OCGParser.XObjectOperator
Class that knows how to process XObject operators.
-
Field Summary
Fields Modifier and Type Field Description protected java.io.ByteArrayOutputStream
baos
The OutputStream of this worker object.static java.lang.String
DEFAULTOPERATOR
Constant used for the default operator.protected int
mc_balance
Keeps track of BMC/EMC balance.protected java.util.Set<java.lang.String>
ocgs
The OCGs that need to be removed.protected static java.util.Map<java.lang.String,OCGParser.PdfOperator>
operators
A map with all supported operators operators (PDF syntax).protected PdfDictionary
properties
The OCG properties.protected java.util.Set<PdfName>
xobj
The names of XObjects that shouldn't be shown.
-
Constructor Summary
Constructors Constructor Description OCGParser(java.util.Set<java.lang.String> ocgs)
Creates an instance of the OCGParser.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
checkMarkedContentEnd()
Keeps track of the MarkedContent state.protected void
checkMarkedContentStart(PdfName ocref)
Keeps track of the MarkedContent state.protected boolean
isToRemoved()
Checks if the parser is currently parsing content that needs to be ignored.protected boolean
isVisible(java.util.List<PdfObject> operands)
Checks operands to find out if the corresponding operator needs to be present or not.void
parse(PRStream stream, PdfDictionary resources)
Parses a stream object and removes OCGs.protected static void
populateOperators()
Populates the operators variable.protected void
println(PdfObject o)
Writes a PDF object to the OutputStream, followed by a newline character.protected void
printsp(PdfObject o)
Writes a PDF object to the OutputStream, followed by a space character.protected void
process(PdfLiteral operator, java.util.List<PdfObject> operands, boolean removable)
Processes an operatorprotected static void
processOperator(OCGParser parser, PdfLiteral operator, java.util.List<PdfObject> operands)
Processes an operator.
-
-
-
Field Detail
-
DEFAULTOPERATOR
public static final java.lang.String DEFAULTOPERATOR
Constant used for the default operator.- See Also:
- Constant Field Values
-
operators
protected static final java.util.Map<java.lang.String,OCGParser.PdfOperator> operators
A map with all supported operators operators (PDF syntax).
-
baos
protected java.io.ByteArrayOutputStream baos
The OutputStream of this worker object.
-
mc_balance
protected int mc_balance
Keeps track of BMC/EMC balance.
-
xobj
protected java.util.Set<PdfName> xobj
The names of XObjects that shouldn't be shown.
-
ocgs
protected java.util.Set<java.lang.String> ocgs
The OCGs that need to be removed.
-
properties
protected PdfDictionary properties
The OCG properties.
-
-
Method Detail
-
parse
public void parse(PRStream stream, PdfDictionary resources) throws java.io.IOException
Parses a stream object and removes OCGs.- Parameters:
stream
- a stream objectresources
- the resources dictionary of that object (containing info about the OCGs)- Throws:
java.io.IOException
-
processOperator
protected static void processOperator(OCGParser parser, PdfLiteral operator, java.util.List<PdfObject> operands) throws java.lang.Exception
Processes an operator.- Parameters:
parser
- the parser that needs to process the operatoroperator
- the operatoroperands
- its operands- Throws:
java.lang.Exception
-
populateOperators
protected static void populateOperators()
Populates the operators variable.
-
isVisible
protected boolean isVisible(java.util.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, java.util.List<PdfObject> operands, boolean removable) throws java.io.IOException
Processes an operator- Parameters:
operator
- the operatoroperands
- its operandsremovable
- is the operator eligable for removal?- Throws:
java.io.IOException
-
printsp
protected void printsp(PdfObject o) throws java.io.IOException
Writes a PDF object to the OutputStream, followed by a space character.- Parameters:
o
-- Throws:
java.io.IOException
-
println
protected void println(PdfObject o) throws java.io.IOException
Writes a PDF object to the OutputStream, followed by a newline character.- Parameters:
o
-- Throws:
java.io.IOException
-
-