Class PdfOCProperties
java.lang.Object
com.itextpdf.kernel.pdf.PdfObjectWrapper<PdfDictionary>
com.itextpdf.kernel.pdf.layer.PdfOCProperties
This class represents /OCProperties entry if pdf catalog and manages
the layers of the pdf document.
To be able to be wrapped with this PdfObjectWrapper the PdfObject
must be indirect.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionPdfOCProperties(PdfDictionary ocPropertiesDict) Creates a new PdfOCProperties instance by the dictionary it represents, the dictionary must be an indirect object.PdfOCProperties(PdfDocument document) Creates a new PdfOCProperties instance. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidaddASEvent(PdfName event, PdfName category) Populates the /AS entry in the /D dictionary.voidaddOCGRadioGroup(List<PdfLayer> group) Use this method to set a collection of optional content groups whose states are intended to follow a "radio button" paradigm.static booleancheckDDictonaryFieldValue(PdfName field, PdfObject value) Checks if optional content group default configuration dictionary field value matches the required value for this field, if one exists.private static voidcopyDDictionaryField(PdfName fieldToAdd, PdfDictionary fromDictionary, PdfDictionary toDictionary) private StringFills the underlying PdfDictionary object with the current layers and their settings.fillDictionary(boolean removeNonDocumentOcgs) Fills the underlying PdfDictionary object with the current layers and their settings.voidflush()protected PdfDocumentGets thePdfDocumentthat owns that OCProperties.Gets the list of all the layers currently registered in the OCProperties.private static voidgetOCGOrder(PdfArray order, PdfLayer layer) Gets the order of the layers in which they will be displayed in the layer view panel, including nesting.protected booleanDefines if the object behind this wrapper must be an indirect object in the resultant document.private voidReads the layers from the document to be able to modify them in the future.private voidreadOrderFromDictionary(PdfLayer parent, PdfArray orderArray, Map<PdfIndirectReference, PdfLayer> layerMap, Set<PdfIndirectReference> layerReferences, Map<PdfString, PdfLayer> titleLayers) Reads the /Order in the /D entry and initialized the parent-child hierarchy.protected voidregisterLayer(PdfLayer layer) This method registers a new layer in the OCProperties.private void
-
Field Details
-
OC_CONFIG_NAME_PATTERN
- See Also:
-
layers
-
-
Constructor Details
-
PdfOCProperties
Creates a new PdfOCProperties instance.- Parameters:
document- the document the optional content belongs to
-
PdfOCProperties
Creates a new PdfOCProperties instance by the dictionary it represents, the dictionary must be an indirect object.- Parameters:
ocPropertiesDict- the dictionary of optional content properties, must have an indirect reference.
-
-
Method Details
-
addOCGRadioGroup
Use this method to set a collection of optional content groups whose states are intended to follow a "radio button" paradigm. That is, the state of at most one optional content group in the array should be ON at a time: if one group is turned ON, all others must be turned OFF.- Parameters:
group- the radio group
-
fillDictionary
Fills the underlying PdfDictionary object with the current layers and their settings. Note that it completely regenerates the dictionary, so your direct changes to the dictionary will not take any affect.- Returns:
- the resultant dictionary
-
fillDictionary
Fills the underlying PdfDictionary object with the current layers and their settings. Note that it completely regenerates the dictionary, so your direct changes to the dictionary will not take any affect.- Parameters:
removeNonDocumentOcgs- the flag indicating whether it is necessary to delete OCGs not from the current document- Returns:
- the resultant dictionary
-
checkDDictonaryFieldValue
Checks if optional content group default configuration dictionary field value matches the required value for this field, if one exists.- Parameters:
field- default configuration dictionary field.value- value of that field.- Returns:
- boolean indicating if field meets requirement.
-
flush
public void flush()- Overrides:
flushin classPdfObjectWrapper<PdfDictionary>
-
getLayers
-
isWrappedObjectMustBeIndirect
protected boolean isWrappedObjectMustBeIndirect()Description copied from class:PdfObjectWrapperDefines if the object behind this wrapper must be an indirect object in the resultant document.
If this method returns true it doesn't necessarily mean that object must be in the indirect state at any moment, but rather defines that when the object will be written to the document it will be transformed into indirect object if it's not indirect yet.
Return value of this method shouldn't depend on any logic, it should return always true or false.- Specified by:
isWrappedObjectMustBeIndirectin classPdfObjectWrapper<PdfDictionary>- Returns:
- true if in the resultant document the object behind the wrapper must be indirect, otherwise false.
-
registerLayer
This method registers a new layer in the OCProperties.- Parameters:
layer- the new layer- Throws:
IllegalArgumentException- if layer param is null
-
getDocument
Gets thePdfDocumentthat owns that OCProperties.- Returns:
- the
PdfDocumentthat owns that OCProperties
-
getOCGOrder
-
copyDDictionaryField
private static void copyDDictionaryField(PdfName fieldToAdd, PdfDictionary fromDictionary, PdfDictionary toDictionary) -
removeNotRegisteredOcgs
private void removeNotRegisteredOcgs() -
addASEvent
-
readLayersFromDictionary
private void readLayersFromDictionary()Reads the layers from the document to be able to modify them in the future. -
readOrderFromDictionary
private void readOrderFromDictionary(PdfLayer parent, PdfArray orderArray, Map<PdfIndirectReference, PdfLayer> layerMap, Set<PdfIndirectReference> layerReferences, Map<PdfString, PdfLayer> titleLayers) Reads the /Order in the /D entry and initialized the parent-child hierarchy. -
createUniqueName
-