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 voidaddAssociatedFile(PdfFileSpec fs)Adds file associated with structure element and identifies the relationship between them.voidaddAssociatedFile(java.lang.String description, PdfFileSpec fs)Adds file associated with structure element and identifies the relationship between them.PdfMcraddKid(int index, PdfMcr kid)PdfStructElemaddKid(int index, PdfStructElem kid)PdfMcraddKid(PdfMcr kid)PdfStructElemaddKid(PdfStructElem kid)(package private) static voidaddKidObject(PdfDictionary parent, int index, PdfObject kid)private voidaddKidObjectToStructElemList(PdfObject k, java.util.List<IStructureNode> list)voidaddRef(PdfStructElem ref)APdfName.Refidentifies the structure element to which the item of content, contained within this structure element, refers (e.g.private IStructureNodeconvertPdfObjectToIPdfStructElem(PdfObject obj)voidflush()PdfStringgetActualText()PdfStringgetAlt()PdfArraygetAssociatedFiles(boolean create)Returns files associated with structure element.PdfObjectgetAttributes(boolean createNewIfNull)Gets attributes object.java.util.List<PdfStructureAttributes>getAttributesList()Gets a list of PDF attribute objects.private PdfDocumentgetDocEnsureIndirectForKids()protected PdfDocumentgetDocument()PdfStringgetE()PdfObjectgetK()java.util.List<IStructureNode>getKids()Gets list of the direct kids of structure element.PdfStringgetLang()PdfNamespacegetNamespace()A namespace this element belongs to (see ISO 32000-2 14.7.4, "Namespaces").IStructureNodegetParent()PdfStringgetPhoneme()Attribute for a structure element that may be used as pronunciation hint.PdfNamegetPhoneticAlphabet()Attribute for a structure element that indicates the phonetic alphabet used by aPdfName.Phonemeattribute.java.util.List<PdfStructElem>getRefsList()APdfName.Refidentifies the structure element or elements to which the item of content, contained within this structure element, refers (e.g.PdfNamegetRole()PdfStringgetStructureElementId()Gets the structure element's ID string, if it has one.booleanisKidFlushed(int index)Checks if the kid with the given index is flushed.static booleanisStructElem(PdfDictionary dictionary)Method to distinguish struct elements from other elements of the logical tree (like mcr or struct tree root).protected booleanisWrappedObjectMustBeIndirect()Defines if the object behind this wrapper must be an indirect object in the resultant document.PdfStructElemput(PdfName key, PdfObject value)IStructureNoderemoveKid(int index)IStructureNoderemoveKid(int index, boolean prepareForReAdding)intremoveKid(IStructureNode kid)private intremoveKidObject(PdfObject kid)private static intremoveObjectFromArray(PdfArray array, PdfObject toRemove)voidsetActualText(PdfString actualText)voidsetAlt(PdfString alt)voidsetAttributes(PdfObject attributes)voidsetE(PdfString e)voidsetLang(PdfString lang)voidsetNamespace(PdfNamespace namespace)A namespace this element belongs to (see ISO 32000-2 14.7.4, "Namespaces").voidsetPhoneme(PdfString elementPhoneme)Attribute for a structure element that may be used as pronunciation hint.voidsetPhoneticAlphabet(PdfName phoneticAlphabet)Attribute for a structure element that indicates the phonetic alphabet used by aPdfName.Phonemeattribute.voidsetRole(PdfName role)voidsetStructureElementId(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- thePdfDictionaryto check on containing struct elements- Returns:
- if the type of
PdfDictionaryis StructElem orPdfDictionarycontains 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. Passtrueif 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:
getRolein 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:
getParentin 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 anullin the list on it's place.- Specified by:
getKidsin 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:
trueif the kid with the given index is flushed,falseotherwise.
-
getK
public PdfObject getK()
-
getRefsList
public java.util.List<PdfStructElem> getRefsList()
APdfName.Refidentifies 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.Refidentifies 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- aPdfStructElemto 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
PdfNamespacethis 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- aPdfNamespacethis 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- aPdfStringwhich 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
PdfStringwhich 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.Phonemeattribute. 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- thePdfNamewhich defines phonetic alphabet used by aPdfName.Phonemeattribute. Possible values are:PdfName.ipafor the International Phonetic Alphabet by the International Phonetic Association;PdfName.x_sampafor Extended Speech Assessment Methods Phonetic Alphabet (X-SAMPA);PdfName.zh_Latn_pinyinfor Pinyin Latin romanization (Mandarin);PdfName.zh_Latn_wadegilefor Wade-Giles romanization (Mandarin).
-
getPhoneticAlphabet
public PdfName getPhoneticAlphabet()
Attribute for a structure element that indicates the phonetic alphabet used by aPdfName.Phonemeattribute. Applies to the structure element and its children, except where overridden by a child structure element.- Returns:
- the
PdfNamewhich 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:
flushin classPdfObjectWrapper<PdfDictionary>
-
addKidObject
static void addKidObject(PdfDictionary parent, int index, PdfObject kid)
-
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.
-
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)
-
-