Class CanvasTag

  • Direct Known Subclasses:
    CanvasArtifact

    public class CanvasTag
    extends java.lang.Object
    This class represents a single tag on a single piece of marked content.

    In Tagged PDF, a tag is the basic structure unit for marking content. The tag structure and hierarchy is largely comparable to HTML. As in HTML, every tag type has a name, defined here in the role attribute. The tagging mechanism in Tagged PDF is extensible, so PDF creators can choose to create custom tags.

    • Field Detail

      • role

        protected PdfName role
        The type of the tag.
      • properties

        protected PdfDictionary properties
        The properties of the tag.
    • Constructor Detail

      • CanvasTag

        public CanvasTag​(PdfName role)
        Creates a tag that is referenced to the document's tag structure (i.e. logical structure).
        Parameters:
        role - the type of tag
      • CanvasTag

        public CanvasTag​(PdfName role,
                         int mcid)
        Creates a tag that is referenced to the document's tag structure (i.e. logical structure).
        Parameters:
        role - the type of tag
        mcid - marked content id which serves as a reference to the document's logical structure
      • CanvasTag

        public CanvasTag​(PdfMcr mcr)
        Creates a tag that is referenced to the document's tag structure (i.e. logical structure).
        Parameters:
        mcr - the Marked Content Reference wrapper object
    • Method Detail

      • getRole

        public PdfName getRole()
        Get the role of the tag.
        Returns:
        the role of the tag as a PdfName
      • getMcid

        public int getMcid()
        Get the marked content id of the tag.
        Returns:
        marked content id
        Throws:
        java.lang.IllegalStateException - if there is no MCID
      • hasMcid

        public boolean hasMcid()
        Determine if an MCID is available
        Returns:
        true if the MCID is available, false otherwise
      • setProperties

        public CanvasTag setProperties​(PdfDictionary properties)
        Sets a dictionary of properties to the tag's properties. All existing properties (if any) will be lost.
        Parameters:
        properties - a dictionary
        Returns:
        current CanvasTag
      • addProperty

        public CanvasTag addProperty​(PdfName name,
                                     PdfObject value)
        Adds a single property to the tag's properties.
        Parameters:
        name - a key
        value - the value for the key
        Returns:
        current CanvasTag
      • removeProperty

        public CanvasTag removeProperty​(PdfName name)
        Removes a single property from the tag's properties.
        Parameters:
        name - the key of the key-value pair to be removed
        Returns:
        current CanvasTag
      • getProperty

        public PdfObject getProperty​(PdfName name)
        Gets a property from the tag's properties dictionary.
        Parameters:
        name - the key of the key-value pair to be retrieved
        Returns:
        the value corresponding to the key
      • getProperties

        public PdfDictionary getProperties()
        Get the properties of the tag.
        Returns:
        properties of the tag
      • getActualText

        public java.lang.String getActualText()
        Gets value of /ActualText property.
        Returns:
        actual text value or null if actual text is not defined
      • getExpansionText

        public java.lang.String getExpansionText()
      • getPropertyAsString

        private java.lang.String getPropertyAsString​(PdfName name)
      • ensurePropertiesInit

        private void ensurePropertiesInit()