Package com.itextpdf.kernel.pdf.layer
Class PdfOCProperties
- java.lang.Object
-
- com.itextpdf.kernel.pdf.PdfObjectWrapper<PdfDictionary>
-
- com.itextpdf.kernel.pdf.layer.PdfOCProperties
-
public class PdfOCProperties extends PdfObjectWrapper<PdfDictionary>
This class represents /OCProperties entry if pdf catalog and manages the layers of the pdf document.To be able to be wrapped with this
PdfObjectWrapperthePdfObjectmust be indirect.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<PdfLayer>layers(package private) static java.lang.StringOC_CONFIG_NAME_PATTERN
-
Constructor Summary
Constructors Constructor Description PdfOCProperties(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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidaddASEvent(PdfName event, PdfName category)Populates the /AS entry in the /D dictionary.voidaddOCGRadioGroup(java.util.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 java.lang.StringcreateUniqueName()PdfObjectfillDictionary()Fills the underlying PdfDictionary object with the current layers and their settings.PdfObjectfillDictionary(boolean removeNonDocumentOcgs)Fills the underlying PdfDictionary object with the current layers and their settings.voidflush()protected PdfDocumentgetDocument()Gets thePdfDocumentthat owns that OCProperties.java.util.List<PdfLayer>getLayers()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 booleanisWrappedObjectMustBeIndirect()Defines if the object behind this wrapper must be an indirect object in the resultant document.private voidreadLayersFromDictionary()Reads the layers from the document to be able to modify them in the future.private voidreadOrderFromDictionary(PdfLayer parent, PdfArray orderArray, java.util.Map<PdfIndirectReference,PdfLayer> layerMap, java.util.Set<PdfIndirectReference> layerReferences, java.util.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 voidremoveNotRegisteredOcgs()-
Methods inherited from class com.itextpdf.kernel.pdf.PdfObjectWrapper
ensureObjectIsAddedToDocument, ensureUnderlyingObjectHasIndirectReference, getPdfObject, isFlushed, makeIndirect, makeIndirect, markObjectAsIndirect, setForbidRelease, setModified, setPdfObject, unsetForbidRelease
-
-
-
-
Field Detail
-
OC_CONFIG_NAME_PATTERN
static final java.lang.String OC_CONFIG_NAME_PATTERN
- See Also:
- Constant Field Values
-
layers
private java.util.List<PdfLayer> layers
-
-
Constructor Detail
-
PdfOCProperties
public PdfOCProperties(PdfDocument document)
Creates a new PdfOCProperties instance.- Parameters:
document- the document the optional content belongs to
-
PdfOCProperties
public PdfOCProperties(PdfDictionary ocPropertiesDict)
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 Detail
-
addOCGRadioGroup
public void addOCGRadioGroup(java.util.List<PdfLayer> group)
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
public PdfObject 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
public PdfObject fillDictionary(boolean removeNonDocumentOcgs)
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
public static boolean checkDDictonaryFieldValue(PdfName field, PdfObject value)
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
public java.util.List<PdfLayer> getLayers()
Gets the list of all the layers currently registered in the OCProperties. Note that this is just a new list and modifications to it will not affect anything.- Returns:
- list of all the
layerscurrently registered in the OCProperties
-
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
protected void registerLayer(PdfLayer layer)
This method registers a new layer in the OCProperties.- Parameters:
layer- the new layer- Throws:
java.lang.IllegalArgumentException- if layer param is null
-
getDocument
protected PdfDocument getDocument()
Gets thePdfDocumentthat owns that OCProperties.- Returns:
- the
PdfDocumentthat owns that OCProperties
-
getOCGOrder
private static void getOCGOrder(PdfArray order, PdfLayer layer)
Gets the order of the layers in which they will be displayed in the layer view panel, including nesting.
-
copyDDictionaryField
private static void copyDDictionaryField(PdfName fieldToAdd, PdfDictionary fromDictionary, PdfDictionary toDictionary)
-
removeNotRegisteredOcgs
private void removeNotRegisteredOcgs()
-
addASEvent
private void addASEvent(PdfName event, PdfName category)
Populates the /AS entry in the /D dictionary.
-
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, java.util.Map<PdfIndirectReference,PdfLayer> layerMap, java.util.Set<PdfIndirectReference> layerReferences, java.util.Map<PdfString,PdfLayer> titleLayers)
Reads the /Order in the /D entry and initialized the parent-child hierarchy.
-
createUniqueName
private java.lang.String createUniqueName()
-
-