Skip to main content
All docs
V26.1
  • PdfDocument.StructureTree Property

    Gets the PDF document structure tree.

    Namespace: DevExpress.Docs.Pdf

    Assembly: DevExpress.Docs.Pdf.v26.1.dll

    Declaration

    public StructureTree StructureTree { get; }

    Property Value

    Type Description
    StructureTree

    PDF document structure tree.

    Remarks

    A tagged PDF document contains a structure tree, a logical representation of the element hierarchy. Assistive technologies, such as screen readers, use the structure tree to identify and navigate document content.

    The PdfDocument.StructureTree property returns a PDF document structure tree. Each structure tree node is a StructureElement object. Call the StructureTree.AddChildElement(StructureTypeDescriptor) method to add a child element to the structure tree. The following classes list available type descriptors that you can pass as parameters:

    Example

    How to: Create a New Tagged PDF Document

    The following code snippet creates a new tagged PDF document.

    using DevExpress.Docs.Pdf;
    using DevExpress.Drawing.Printing;
    using System.Drawing;
    using System.IO;
    
    using (PdfDocument document = new PdfDocument())
    {
        Page page = document.Pages.Add(DXPaperKind.A4);
    
        // Create the root Document element.
        StructureElement doc = document.StructureTree
            .AddChildElement(Pdf17StructureType.Document);
        // Add a section to the document.
        StructureElement section =
            doc.AddChildElement(Pdf17StructureType.Sect);
    
        // Add a heading.
        StructureElement heading =
            section.AddChildElement(Pdf17StructureType.H1);
        heading.AddFragment(page, new TextFragment
        {
            Text = "Invoice",
            Location = new PointF(50, 800),
            Font = new TextFont("Arial", TextFontStyle.Bold),
            FontSize = 24
        });
    
        // Create a table with layout attributes.
        StructureElement table =
            section.AddChildElement(Pdf17StructureType.Table);
        table.Attributes.Add(new LayoutAttribute
        {
            Placement = LayoutPlacement.Block,
            WritingMode = WritingMode.LeftToRight
        });
        table.Attributes.Add(
            new TableAttribute { Summary = "Invoice items" });
        StructureElement header =
            table.AddChildElement(Pdf17StructureType.THead);
        StructureElement headerRow =
            header.AddChildElement(Pdf17StructureType.TR);
    
        // Add table header cells.
        StructureElement th1 =
            headerRow.AddChildElement(Pdf17StructureType.TH);
        th1.Attributes.Add(
            new TableAttribute { Scope = TableScope.Column });
        th1.AddFragment(page, new TextFragment
        {
            Text = "Item",
            Location = new PointF(50, 700),
            Font = new TextFont("Arial", TextFontStyle.Bold),
            FontSize = 12
        });
    
        StructureElement th2 =
            headerRow.AddChildElement(Pdf17StructureType.TH);
        th2.Attributes.Add(
            new TableAttribute { Scope = TableScope.Column });
        th2.AddFragment(page, new TextFragment
        {
            Text = "Qty",
            Location = new PointF(250, 700),
            Font = new TextFont("Arial", TextFontStyle.Bold),
        });
    
        StructureElement th3 =
            headerRow.AddChildElement(Pdf17StructureType.TH);
        th3.Attributes.Add(
            new TableAttribute { Scope = TableScope.Column });
        th3.AddFragment(page, new TextFragment
        {
            Text = "Price",
            Location = new PointF(320, 700),
            Font = new TextFont("Arial", TextFontStyle.Bold)
        });
    
        StructureElement th4 =
            headerRow.AddChildElement(Pdf17StructureType.TH);
        th4.Attributes.Add(
            new TableAttribute { Scope = TableScope.Column });
        th4.AddFragment(page, new TextFragment
        {
            Text = "Total",
            Location = new PointF(400, 700),
            Font = new TextFont("Arial", TextFontStyle.Bold),
        });
    
        // Add table body with a data row.
        StructureElement body =
            table.AddChildElement(Pdf17StructureType.TBody);
        StructureElement dataRow =
            body.AddChildElement(Pdf17StructureType.TR);
    
        StructureElement td1 =
            dataRow.AddChildElement(Pdf17StructureType.TD);
        td1.AddFragment(page, new TextFragment
        {
            Text = "Product A",
            Location = new PointF(50, 670)
        });
    
        StructureElement td2 =
            dataRow.AddChildElement(Pdf17StructureType.TD);
        td2.AddFragment(page, new TextFragment
        {
            Text = "2",
            Location = new PointF(250, 670)
        });
    
        StructureElement td3 =
            dataRow.AddChildElement(Pdf17StructureType.TD);
        td3.AddFragment(page, new TextFragment
        {
            Text = "$25.00",
            Location = new PointF(320, 670)
        });
    
        StructureElement td4 =
            dataRow.AddChildElement(Pdf17StructureType.TD);
        td4.AddFragment(page, new TextFragment
        {
            Text = "$50.00",
            Location = new PointF(400, 670)
        });
    
        // Add a paragraph with the total amount.
        StructureElement pTotal =
            section.AddChildElement(Pdf17StructureType.P);
        pTotal.AddFragment(page, new TextFragment
        {
            Text = "Total: $50.00",
            Location = new PointF(50, 620),
            Font = new TextFont("Arial", TextFontStyle.Bold),
        });
    
        // Save the tagged document.
        using (FileStream stream =
            File.Create("TaggedInvoice.pdf"))
        {
            document.Save(stream);
        }
    }
    
    See Also