Skip to main content

StructureTree Class

Defines the structure tree for a tagged PDF document.

Declaration

public class StructureTree extends JavaObject

Remarks

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);
            }
        }
    }
}

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

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
com.devexpress.system.JavaObject
StructureTree

StructureTree()

Initializes a new instance of the StructureTree class.

Declaration

public StructureTree()

Methods

addChildElement(Pdf17StructureType structureType) Method

Adds a top-level 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 top-level structure element.

addChildElement(Pdf20StructureType structureType) Method

Adds a top-level 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 top-level structure element.

addChildElement(StructureTypeDescriptor descriptor) Method

Adds a top-level structure element with the specified structure type descriptor.

Declaration

public StructureElement addChildElement(StructureTypeDescriptor descriptor)

Parameters

Name Type Description
descriptor StructureTypeDescriptor

The structure type descriptor.

Returns

Type Description
StructureElement

The added top-level structure element.

getElements() Method

Returns top-level structure elements.

Declaration

public IStructureElementCollection getElements()

Returns

Type Description
IStructureElementCollection

Top-level structure elements.

getNamespaces() Method

Returns namespaces associated with the document structure tree.

Declaration

public List<PdfNamespace> getNamespaces()

Returns

Type Description
java.util.List<PdfNamespace>

Namespaces associated with the document structure tree.

Remarks

The StructureTree.getNamespaces() method returns namespaces associated with the document structure tree. Use namespaces to define custom structure types based on PDF 2.0 extension vocabularies or other non-standard structure vocabularies.

Standard structure types defined by PDF 1.7 or PDF 2.0 do not require manual namespace configuration.

getRoleMap() Method

Returns the structure tree role map.

Declaration

public Map<String,String> getRoleMap()

Returns

Type Description
java.util.Map<java.lang.String,java.lang.String>

The structure tree role map.