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 Summary
Constructors Constructor Description PdfStructElem(PdfDictionary pdfObject)
PdfStructElem(PdfDocument document, PdfName role)
PdfStructElem(PdfDocument document, PdfName role, PdfAnnotation annot)
PdfStructElem(PdfDocument document, PdfName role, PdfPage page)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addAssociatedFile(PdfFileSpec fs)
Adds file associated with structure element and identifies the relationship between them.void
addAssociatedFile(java.lang.String description, PdfFileSpec fs)
Adds file associated with structure element and identifies the relationship between them.PdfMcr
addKid(int index, PdfMcr kid)
PdfStructElem
addKid(int index, PdfStructElem kid)
PdfMcr
addKid(PdfMcr kid)
PdfStructElem
addKid(PdfStructElem kid)
(package private) static void
addKidObject(PdfDictionary parent, int index, PdfObject kid)
private void
addKidObjectToStructElemList(PdfObject k, java.util.List<IStructureNode> list)
void
addRef(PdfStructElem ref)
APdfName.Ref
identifies the structure element to which the item of content, contained within this structure element, refers (e.g.private IStructureNode
convertPdfObjectToIPdfStructElem(PdfObject obj)
void
flush()
PdfString
getActualText()
PdfString
getAlt()
PdfArray
getAssociatedFiles(boolean create)
Returns files associated with structure element.PdfObject
getAttributes(boolean createNewIfNull)
Gets attributes object.java.util.List<PdfStructureAttributes>
getAttributesList()
Gets a list of PDF attribute objects.private PdfDocument
getDocEnsureIndirectForKids()
protected PdfDocument
getDocument()
PdfString
getE()
PdfObject
getK()
java.util.List<IStructureNode>
getKids()
Gets list of the direct kids of structure element.PdfString
getLang()
PdfNamespace
getNamespace()
A namespace this element belongs to (see ISO 32000-2 14.7.4, "Namespaces").IStructureNode
getParent()
PdfString
getPhoneme()
Attribute for a structure element that may be used as pronunciation hint.PdfName
getPhoneticAlphabet()
Attribute for a structure element that indicates the phonetic alphabet used by aPdfName.Phoneme
attribute.java.util.List<PdfStructElem>
getRefsList()
APdfName.Ref
identifies the structure element or elements to which the item of content, contained within this structure element, refers (e.g.PdfName
getRole()
PdfString
getStructureElementId()
Gets the structure element's ID string, if it has one.boolean
isKidFlushed(int index)
Checks if the kid with the given index is flushed.static boolean
isStructElem(PdfDictionary dictionary)
Method to distinguish struct elements from other elements of the logical tree (like mcr or struct tree root).protected boolean
isWrappedObjectMustBeIndirect()
Defines if the object behind this wrapper must be an indirect object in the resultant document.PdfStructElem
put(PdfName key, PdfObject value)
IStructureNode
removeKid(int index)
IStructureNode
removeKid(int index, boolean prepareForReAdding)
int
removeKid(IStructureNode kid)
private int
removeKidObject(PdfObject kid)
private static int
removeObjectFromArray(PdfArray array, PdfObject toRemove)
void
setActualText(PdfString actualText)
void
setAlt(PdfString alt)
void
setAttributes(PdfObject attributes)
void
setE(PdfString e)
void
setLang(PdfString lang)
void
setNamespace(PdfNamespace namespace)
A namespace this element belongs to (see ISO 32000-2 14.7.4, "Namespaces").void
setPhoneme(PdfString elementPhoneme)
Attribute for a structure element that may be used as pronunciation hint.void
setPhoneticAlphabet(PdfName phoneticAlphabet)
Attribute for a structure element that indicates the phonetic alphabet used by aPdfName.Phoneme
attribute.void
setRole(PdfName role)
void
setStructureElementId(PdfString id)
Sets the structure element's ID string.-
Methods inherited from class com.itextpdf.kernel.pdf.PdfObjectWrapper
ensureObjectIsAddedToDocument, ensureUnderlyingObjectHasIndirectReference, getPdfObject, isFlushed, makeIndirect, makeIndirect, markObjectAsIndirect, setForbidRelease, setModified, setPdfObject, unsetForbidRelease
-
-
-
-
Constructor Detail
-
PdfStructElem
public PdfStructElem(PdfDictionary pdfObject)
-
PdfStructElem
public PdfStructElem(PdfDocument document, PdfName role, PdfPage page)
-
PdfStructElem
public PdfStructElem(PdfDocument document, PdfName role, PdfAnnotation annot)
-
PdfStructElem
public PdfStructElem(PdfDocument document, PdfName role)
-
-
Method Detail
-
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
- thePdfDictionary
to check on containing struct elements- Returns:
- if the type of
PdfDictionary
is StructElem orPdfDictionary
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. Passtrue
if you want to create empty dictionary in such case. The attributes dictionary will be stored inside element.- Returns:
- attributes dictionary.
-
getAttributesList
public java.util.List<PdfStructureAttributes> getAttributesList()
Gets a list of PDF attribute objects.- Returns:
- list of PDF attribute objects.
-
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 interfaceIStructureNode
-
setRole
public void setRole(PdfName role)
-
addKid
public PdfStructElem addKid(PdfStructElem kid)
-
addKid
public PdfStructElem addKid(int index, PdfStructElem 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 interfaceIStructureNode
- 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 java.util.List<IStructureNode> getKids()
Gets list of the direct kids of structure element. If certain kid is flushed, there will be anull
in the list on it's place.- Specified by:
getKids
in interfaceIStructureNode
- Returns:
- list of the direct kids of structure element.
-
isKidFlushed
public boolean isKidFlushed(int index)
Checks if the kid with the given index is flushed.- Parameters:
index
- index of the kid to check.- Returns:
true
if the kid with the given index is flushed,false
otherwise.
-
getK
public PdfObject getK()
-
getRefsList
public java.util.List<PdfStructElem> getRefsList()
APdfName.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)
APdfName.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
- aPdfStructElem
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
- aPdfNamespace
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
- aPdfString
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 aPdfName.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
- thePdfName
which defines phonetic alphabet used by aPdfName.Phoneme
attribute. Possible values are:PdfName.ipa
for the International Phonetic Alphabet by the International Phonetic Association;PdfName.x_sampa
for Extended Speech Assessment Methods Phonetic Alphabet (X-SAMPA);PdfName.zh_Latn_pinyin
for Pinyin Latin romanization (Mandarin);PdfName.zh_Latn_wadegile
for Wade-Giles romanization (Mandarin).
-
getPhoneticAlphabet
public PdfName getPhoneticAlphabet()
Attribute for a structure element that indicates the phonetic alphabet used by aPdfName.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 aPdfName.Phoneme
, or null if not defined, default valuePdfName.ipa
. SeesetPhoneticAlphabet(PdfName)
for other possible values.
-
addAssociatedFile
public void addAssociatedFile(java.lang.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 descriptionfs
- 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 classPdfObjectWrapper<PdfDictionary>
-
addKidObject
static void addKidObject(PdfDictionary parent, int index, PdfObject kid)
-
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 classPdfObjectWrapper<PdfDictionary>
- Returns:
- true if in the resultant document the object behind the wrapper must be indirect, otherwise false.
-
getDocument
protected PdfDocument getDocument()
-
getDocEnsureIndirectForKids
private PdfDocument getDocEnsureIndirectForKids()
-
addKidObjectToStructElemList
private void addKidObjectToStructElemList(PdfObject k, java.util.List<IStructureNode> list)
-
convertPdfObjectToIPdfStructElem
private IStructureNode convertPdfObjectToIPdfStructElem(PdfObject obj)
-
removeKidObject
private int removeKidObject(PdfObject kid)
-
-