Class PdfStructElem

java.lang.Object
com.itextpdf.kernel.pdf.PdfObjectWrapper<PdfDictionary>
com.itextpdf.kernel.pdf.tagging.PdfStructElem
All Implemented Interfaces:
IStructureNode

public class PdfStructElem extends PdfObjectWrapper<PdfDictionary> implements IStructureNode
A wrapper for structure element dictionaries (ISO-32000 14.7.2 "Structure Hierarchy").

The logical structure of a document shall be described by a hierarchy of objects called the structure hierarchy or structure tree. At the root of the hierarchy shall be a dictionary object called the structure tree root (see PdfStructTreeRoot). Immediate children of the structure tree root are structure elements. Structure elements are other structure elements or content items.

  • Constructor Details

  • Method Details

    • isStructElem

      public static boolean isStructElem (PdfDictionary dictionary)
      Method to distinguish struct elements from other elements of the logical tree (like mcr or struct tree root).
      Parameters:
      dictionary - the PdfDictionary to check on containing struct elements
      Returns:
      if the type of PdfDictionary is StructElem or PdfDictionary contains the required key S then true, otherwise false
    • getAttributes

      public PdfObject getAttributes (boolean createNewIfNull)
      Gets attributes object.
      Parameters:
      createNewIfNull - sometimes attributes object may not exist. Pass true if you want to create empty dictionary in such case. The attributes dictionary will be stored inside element.
      Returns:
      attributes dictionary.
    • setAttributes

      public void setAttributes (PdfObject attributes)
    • getLang

      public PdfString getLang()
    • setLang

      public void setLang (PdfString lang)
    • getAlt

      public PdfString getAlt()
    • setAlt

      public void setAlt (PdfString alt)
    • getActualText

      public PdfString getActualText()
    • setActualText

      public void setActualText (PdfString actualText)
    • getE

      public PdfString getE()
    • setE

      public void setE (PdfString e)
    • getStructureElementId

      public PdfString getStructureElementId()
      Gets the structure element's ID string, if it has one.
      Returns:
      the structure element's ID string, or null if there is none
    • setStructureElementId

      public void setStructureElementId (PdfString id)
      Sets the structure element's ID string. This value can be used by other structure elements to reference this one.
      Parameters:
      id - the element's ID string to be set
    • getRole

      public PdfName getRole()
      Specified by:
      getRole in interface IStructureNode
    • setRole

      public void setRole (PdfName role)
    • addKid

      public PdfStructElem addKid (PdfStructElem kid)
    • addKid

      public PdfStructElem addKid (int index, PdfStructElem kid)
    • addKid

      public PdfMcr addKid (PdfMcr kid)
    • addKid

      public PdfMcr addKid (int index, PdfMcr kid)
    • removeKid

      public IStructureNode removeKid (int index)
    • removeKid

      public IStructureNode removeKid (int index, boolean prepareForReAdding)
    • removeKid

      public int removeKid (IStructureNode kid)
    • getParent

      public IStructureNode getParent()
      Specified by:
      getParent in interface IStructureNode
      Returns:
      parent of the current structure element. Returns null if parent isn't set or if either current element or parent are invalid.
    • getKids

      public List<IStructureNode> getKids()
      Gets list of the direct kids of structure element. If certain kid is flushed, there will be a null in the list on it's place.
      Specified by:
      getKids in interface IStructureNode
      Returns:
      list of the direct kids of structure element.
    • getK

      public PdfObject getK()
    • getRefsList

      public List<PdfStructElem> getRefsList()
      A PdfName.Ref identifies the structure element or elements to which the item of content, contained within this structure element, refers (e.g. footnotes, endnotes, sidebars, etc.).
      Returns:
      a List<PdfStructElem> containing zero, one or more structure elements.
    • addRef

      public void addRef (PdfStructElem ref)
      A PdfName.Ref identifies the structure element to which the item of content, contained within this structure element, refers (e.g. footnotes, endnotes, sidebars, etc.).

      This value has meaning only for the PDF documents of version 2.0 and higher.

      Parameters:
      ref - a PdfStructElem to which the item of content, contained within this structure element, refers.
    • getNamespace

      public PdfNamespace getNamespace()
      A namespace this element belongs to (see ISO 32000-2 14.7.4, "Namespaces"). If not present, the element shall be considered to be in the default standard structure namespace.
      Returns:
      a PdfNamespace this element belongs to.
    • setNamespace

      public void setNamespace (PdfNamespace namespace)
      A namespace this element belongs to (see ISO 32000-2 14.7.4, "Namespaces").

      This value has meaning only for the PDF documents of version 2.0 and higher.

      Parameters:
      namespace - a PdfNamespace this element belongs to, or null if element is desired to be considered in the default standard structure namespace.
    • setPhoneme

      public void setPhoneme (PdfString elementPhoneme)
      Attribute for a structure element that may be used as pronunciation hint. It is an exact replacement for content enclosed by the structure element and its children.

      This value has meaning only for the PDF documents of version 2.0 and higher.

      Parameters:
      elementPhoneme - a PdfString which defines an exact replacement for content enclosed by the structure element and its children. This value is to be interpreted based on the PhoneticAlphabet attribute in effect.
    • getPhoneme

      public PdfString getPhoneme()
      Attribute for a structure element that may be used as pronunciation hint. It is an exact replacement for content enclosed by the structure element and its children.
      Returns:
      a PdfString which defines an exact replacement for content enclosed by the structure element and its children. This value is to be interpreted based on the PhoneticAlphabet attribute in effect.
    • setPhoneticAlphabet

      public void setPhoneticAlphabet (PdfName phoneticAlphabet)
      Attribute for a structure element that indicates the phonetic alphabet used by a PdfName.Phoneme attribute. Applies to the structure element and its children, except where overridden by a child structure element.

      This value has meaning only for the PDF documents of version 2.0 and higher.

      Parameters:
      phoneticAlphabet - the PdfName which defines phonetic alphabet used by a PdfName.Phoneme attribute. Possible values are: Other values may be used.
    • getPhoneticAlphabet

      public PdfName getPhoneticAlphabet()
      Attribute for a structure element that indicates the phonetic alphabet used by a PdfName.Phoneme attribute. Applies to the structure element and its children, except where overridden by a child structure element.
      Returns:
      the PdfName which defines phonetic alphabet used by a PdfName.Phoneme, or null if not defined, default value PdfName.ipa. See setPhoneticAlphabet(PdfName) for other possible values.
    • addAssociatedFile

      public void addAssociatedFile (String description, PdfFileSpec fs)
      Adds file associated with structure element and identifies the relationship between them.

      Associated files may be used in Pdf/A-3 and Pdf 2.0 documents. The method adds file to array value of the AF key in the structure element dictionary. If description is provided, it also will add file description to catalog Names tree.

      For associated files their associated file specification dictionaries shall include the AFRelationship key

      Parameters:
      description - the file description
      fs - file specification dictionary of associated file
    • addAssociatedFile

      public void addAssociatedFile (PdfFileSpec fs)

      Adds file associated with structure element and identifies the relationship between them.

      Associated files may be used in Pdf/A-3 and Pdf 2.0 documents. The method adds file to array value of the AF key in the structure element dictionary.

      For associated files their associated file specification dictionaries shall include the AFRelationship key

      Parameters:
      fs - file specification dictionary of associated file
    • getAssociatedFiles

      public PdfArray getAssociatedFiles (boolean create)
      Returns files associated with structure element.
      Parameters:
      create - defines whether AF arrays will be created if it doesn't exist
      Returns:
      associated files array
    • put

      public PdfStructElem put (PdfName key, PdfObject value)
    • flush

      public void flush()
      Overrides:
      flush in class PdfObjectWrapper<PdfDictionary>
    • 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()