Class PdfLayerMembership

java.lang.Object
com.itextpdf.kernel.pdf.PdfObjectWrapper<PdfDictionary>
com.itextpdf.kernel.pdf.layer.PdfLayerMembership
All Implemented Interfaces:
IPdfOCG

public class PdfLayerMembership extends PdfObjectWrapper<PdfDictionary> implements IPdfOCG
Content typically belongs to a single optional content group, and is visible when the group is ON and invisible when it is OFF. To express more complex visibility policies, content should not declare itself to belong to an optional content group directly, but rather to an optional content membership dictionary represented by this class.

To be able to be wrapped with this PdfObjectWrapper the PdfObject must be indirect.
  • Constructor Details

    • PdfLayerMembership

      public PdfLayerMembership (PdfDocument doc)
      Creates a new, empty membership layer.
      Parameters:
      doc - a PdfDocument where a new empty membership layer creates
    • PdfLayerMembership

      public PdfLayerMembership (PdfDictionary membershipDictionary)
      Creates a new PdfLayerMembership instance by its PdfDictionary, which must be an indirect object.
      Parameters:
      membershipDictionary - the membership dictionary, must have an indirect reference.
  • Method Details

    • getLayers

      public Collection<PdfLayer> getLayers()
      Gets the collection of the layers this layer membership operates with.
      Returns:
      list of layers this layer membership operates with
    • addLayer

      public void addLayer (PdfLayer layer)
      Adds a new layer to the current layer membership.
      Parameters:
      layer - the layer to be added
    • setVisibilityPolicy

      public void setVisibilityPolicy (PdfName visibilityPolicy)
      Sets the visibility policy for content belonging to this membership dictionary. Possible values are AllOn, AnyOn, AnyOff and AllOff. AllOn - Visible only if all of the entries are ON. AnyOn - Visible if any of the entries are ON. AnyOff - Visible if any of the entries are OFF. AllOff - Visible only if all of the entries are OFF. The default value is AnyOn.
      Parameters:
      visibilityPolicy - the visibility policy
    • getVisibilityPolicy

      public PdfName getVisibilityPolicy()
      Gets the visibility policy for content belonging to this optional content membership dictionary.
      Returns:
      the visibility policy for content belonging to this membership dictionary
    • setVisibilityExpression

      public void setVisibilityExpression (PdfVisibilityExpression visibilityExpression)
      Sets the visibility expression for content belonging to this membership dictionary.
      Parameters:
      visibilityExpression - A (nested) array of which the first value is /And, /Or, or /Not followed by a series of indirect references to OCGs or other visibility expressions.
    • getVisibilityExpression

      public PdfVisibilityExpression getVisibilityExpression()
      Gets the visibility expression for content belonging to this optional content membership dictionary.
      Returns:
      the visibility expression for content belonging to this membership dictionary, if not set return null
    • getIndirectReference

      public PdfIndirectReference getIndirectReference()
      Description copied from interface: IPdfOCG
      Gets the PdfIndirectReference that represents this layer.
      Specified by:
      getIndirectReference in interface IPdfOCG
      Returns:
      the PdfIndirectReference that represents this layer
    • isWrappedObjectMustBeIndirect

      protected boolean isWrappedObjectMustBeIndirect()
      Description copied from class: PdfObjectWrapper
      Defines 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:
      isWrappedObjectMustBeIndirect in class PdfObjectWrapper<PdfDictionary>
      Returns:
      true if in the resultant document the object behind the wrapper must be indirect, otherwise false.
    • getDocument

      protected PdfDocument getDocument()
      Gets the PdfDocument that owns that layer membership.
      Returns:
      the PdfDocument that owns that layer membership