Skip to main content

StructureElement Class

A structure element in a tagged PDF document.

Declaration

public class StructureElement extends StructureItem

Remarks

Refer to the following help topic for additional information: Generate and Edit Tagged PDF Documents.

The following code snippet creates a tagged PDF document, configures PDF/UA metadata, and specifies marked content information through the MarkInfo class. The code snippet enables marked content, user properties, and disables the suspects flag before saving the document.

package pdf;

import com.devexpress.docs.pdf.*;
import com.devexpress.system.drawing.*;
import com.devexpress.drawing.printing.*;

import java.io.*;
import java.util.*;
import java.nio.file.*;

public class Main {
    public static void main(String[] args) throws Exception {
        try (PdfDocument document = new PdfDocument()) {
            Locale documentLocale = Locale.forLanguageTag("en-US");
            String title = "Invoice";

            // Specify PDF/UA metadata.
            document.getMetadata().getXmp()
                    .getXmpPdfUASchema()
                    .setPart(new XmpInteger(1));

            document.getMetadata().getXmp()
                    .getXmpDublinCoreSchema()
                    .getTitle()
                    .add(documentLocale.toLanguageTag(), title);

            // Specify marked content information.
            MarkInfo markInfo = document.getMarkInfo();
            markInfo.setMarked(true);
            markInfo.setUserProperties(true);
            markInfo.setSuspects(false);

            Page page = document.getPages().add(DXPaperKind.A4);

            // Create the root Document structure element.
            StructureElement root = document.getStructureTree()
                    .addChildElement(Pdf17StructureType.DOCUMENT);

            // Add a section to the document structure.
            StructureElement section = root.addChildElement(Pdf17StructureType.SECT);

            // Add a heading element.
            StructureElement heading = section.addChildElement(Pdf17StructureType.H1);
            heading.addFragment(page, new TextFragment() {{
                setText(title);
                setLocation(new PointF(50, 800));
                setFont(new TextFont("Arial", TextFontStyle.BOLD));
                setFontSize(24);
            }});

            // Add a paragraph element.
            StructureElement paragraph = section.addChildElement(Pdf17StructureType.P);
            paragraph.addFragment(page, new TextFragment() {{
                setText("Invoice details");
                setLocation(new PointF(50, 760));
            }});

            // Save the tagged PDF document.
            try (OutputStream stream =
                         Files.newOutputStream(
                                 Path.of("TaggedDocument.pdf"))) {
                document.save(stream);
            }
        }
    }
}

Inherited Members

com.devexpress.system.JavaObject.clone()
com.devexpress.system.JavaObject.equals(java.lang.Object)
com.devexpress.system.JavaObject.hashCode()
com.devexpress.system.JavaObject.initFields()
com.devexpress.system.JavaObject.memberwiseClone()
com.devexpress.system.JavaObject.toString()
java.lang.Object.finalize()
java.lang.Object.getClass()
java.lang.Object.notify()
java.lang.Object.notifyAll()
java.lang.Object.wait()
java.lang.Object.wait(long)
java.lang.Object.wait(long,int)

Inheritance

Object
JavaObject
StructureItem
StructureElement

Constructors

StructureElement(Pdf17StructureType structureType) Constructor

Initializes a new structure element with the specified PDF 1.7 structure type.

Declaration

public StructureElement(Pdf17StructureType structureType)

Parameters

Name Type Description
structureType Pdf17StructureType

The PDF 1.7 structure type.

StructureElement(Pdf20StructureType structureType) Constructor

Initializes a new structure element with the specified PDF 2.0 structure type.

Declaration

public StructureElement(Pdf20StructureType structureType)

Parameters

Name Type Description
structureType Pdf20StructureType

The PDF 2.0 structure type.

StructureElement(StructureTypeDescriptor descriptor) Constructor

Initializes a new structure element with the specified structure type descriptor.

Declaration

public StructureElement(StructureTypeDescriptor descriptor)

Parameters

Name Type Description
descriptor StructureTypeDescriptor

The structure type descriptor.

Methods

addAnnotation(Page page, BaseAnnotation annotation) Method

Adds an annotation to the structure element on the specified page.

Declaration

public StructureContentItem addAnnotation(Page page, BaseAnnotation annotation)

Parameters

Name Type Description
page Page

The page that contains the annotation.

annotation BaseAnnotation

The annotation to add.

Returns

Type Description
StructureContentItem

The added content item.

addChildElement(Pdf17StructureType structureType) Method

Adds a child structure element with the specified PDF 1.7 structure type.

Declaration

public StructureElement addChildElement(Pdf17StructureType structureType)

Parameters

Name Type Description
structureType Pdf17StructureType

The PDF 1.7 structure type.

Returns

Type Description
StructureElement

The added child structure element.

addChildElement(Pdf20StructureType structureType) Method

Adds a child structure element with the specified PDF 2.0 structure type.

Declaration

public StructureElement addChildElement(Pdf20StructureType structureType)

Parameters

Name Type Description
structureType Pdf20StructureType

The PDF 2.0 structure type.

Returns

Type Description
StructureElement

The added child structure element.

addChildElement(StructureTypeDescriptor childDescriptor) Method

Adds a child structure element with the specified structure type descriptor.

Declaration

public StructureElement addChildElement(StructureTypeDescriptor childDescriptor)

Parameters

Name Type Description
childDescriptor StructureTypeDescriptor

The child structure type descriptor.

Returns

Type Description
StructureElement

The added child structure element.

addContentReference(Page page, BaseAnnotation annotation) Method

Adds a content reference for the specified annotation on a page.

Declaration

public StructureContentItem addContentReference(Page page, BaseAnnotation annotation)

Parameters

Name Type Description
page Page

The page that contains the annotation.

annotation BaseAnnotation

The annotation content reference.

Returns

Type Description
StructureContentItem

The added content item.

addContentReference(Page page, WidgetAnnotation widgetAnnotation) Method

Adds a content reference for the specified widget annotation on a page.

Declaration

public StructureContentItem addContentReference(Page page, WidgetAnnotation widgetAnnotation)

Parameters

Name Type Description
page Page

The page that contains the widget annotation.

widgetAnnotation WidgetAnnotation

The widget annotation content reference.

Returns

Type Description
StructureContentItem

The added content item.

addFragment(Page page, PageFragment fragment) Method

Adds a page fragment to the structure element on the specified page.

Declaration

public StructureMarkedContentReference addFragment(Page page, PageFragment fragment)

Parameters

Name Type Description
page Page

The page that contains the fragment.

fragment PageFragment

The page fragment to add.

Returns

Type Description
StructureMarkedContentReference

The added structure marked content reference.

addMarkedContentGroup(Page page, MarkedContentGroup group) Method

Adds a marked content group to the structure element on the specified page.

Declaration

public StructureMarkedContentGroup addMarkedContentGroup(Page page, MarkedContentGroup group)

Parameters

Name Type Description
page Page

The page that contains the marked content group.

group MarkedContentGroup

The marked content group to add.

Returns

Type Description
StructureMarkedContentGroup

The added structure marked content group.

addMarkedContentReference(Page page, MarkedContentGroup group, FormTemplate formTemplate) Method

Adds a marked content reference for the specified group and form template on a page.

Declaration

public StructureMarkedContentReference addMarkedContentReference(Page page, MarkedContentGroup group, FormTemplate formTemplate)

Parameters

Name Type Description
page Page

The page that contains the marked content reference.

group MarkedContentGroup

The marked content group.

formTemplate FormTemplate

The form template that contains the marked content.

Returns

Type Description
StructureMarkedContentReference

The added structure marked content reference.

addWidget(Page page, WidgetAnnotation widgetAnnotation) Method

Adds a widget annotation to the structure element on the specified page.

Declaration

public StructureContentItem addWidget(Page page, WidgetAnnotation widgetAnnotation)

Parameters

Name Type Description
page Page

The page that contains the widget annotation.

widgetAnnotation WidgetAnnotation

The widget annotation to add.

Returns

Type Description
StructureContentItem

The added content item.

getAbbreviation() Method

Returns the structure element abbreviation.

Declaration

public String getAbbreviation()

Returns

Type Description
String

The structure element abbreviation.

getActualText() Method

Returns the structure element actual text.

Declaration

public String getActualText()

Returns

Type Description
String

The structure element actual text.

getAlternateDescription() Method

Returns the structure element alternate description.

Declaration

public String getAlternateDescription()

Returns

Type Description
String

The structure element alternate description.

getAttributes() Method

Returns the structure element attributes.

Declaration

public IStructureElementAttributeCollection getAttributes()

Returns

Type Description
IStructureElementAttributeCollection

The structure element attributes.

getDescriptor() Method

Returns the structure element descriptor.

Declaration

public StructureTypeDescriptor getDescriptor()

Returns

Type Description
StructureTypeDescriptor

The structure element descriptor.

getElements() Method

Returns child elements of the structure element.

Declaration

public IStructureElementCollection getElements()

Returns

Type Description
IStructureElementCollection

Child elements of the structure element.

getId() Method

Returns the structure element identifier.

Declaration

public String getId()

Returns

Type Description
String

The structure element identifier.

getLanguageCulture() Method

Returns the structure element language culture.

Declaration

public Locale getLanguageCulture()

Returns

Type Description
Locale

The structure element language culture.

getTitle() Method

Returns the structure element title.

Declaration

public String getTitle()

Returns

Type Description
String

The structure element title.

setAbbreviation(String value) Method

Sets the structure element abbreviation.

Declaration

public void setAbbreviation(String value)

Parameters

Name Type Description
value String

The structure element abbreviation.

setActualText(String value) Method

Sets the structure element actual text.

Declaration

public void setActualText(String value)

Parameters

Name Type Description
value String

The structure element actual text.

setAlternateDescription(String value) Method

Sets the structure element alternate description.

Declaration

public void setAlternateDescription(String value)

Parameters

Name Type Description
value String

The structure element alternate description.

setId(String value) Method

Sets the structure element identifier.

Declaration

public void setId(String value)

Parameters

Name Type Description
value String

The structure element identifier.

setLanguageCulture(Locale value) Method

Sets the structure element language culture.

Declaration

public void setLanguageCulture(Locale value)

Parameters

Name Type Description
value Locale

The structure element language culture.

setTitle(String value) Method

Sets the structure element title.

Declaration

public void setTitle(String value)

Parameters

Name Type Description
value String

The structure element title.