# Tagged PDF

Learn how to create a tagged PDF in DsPdf. Tagged PDF is a PDF containing accessibility markup at the back end that provides it a logical structure.

## Content

Tagged PDF is a PDF containing accessibility markup at the back end which provides it a logical structure that manages the reading order and presentation of the document content. It also allows you to extract the page content, such as text, images, etc., and reuse it. Tagged PDF makes it easy to read a PDF by screen reader software for users who rely on assistive technology. DsPdf allows you to create tagged PDF or structured PDF document by adding different structural elements to the document and rendering the content as marked by using the [BeginMarkedContent](/document-solutions/dot-net-pdf-api/api/online/DS.Documents.Pdf/GrapeCity.Documents.Pdf.GcPdfGraphics.BeginMarkedContent.html) and [EndMarkedContent](/document-solutions/dot-net-pdf-api/api/online/DS.Documents.Pdf/GrapeCity.Documents.Pdf.GcPdfGraphics.EndMarkedContent.html) methods.

## Create Tagged PDF files

To create a tagged PDF:

1. Create a Part element using the [StructElement](/document-solutions/dot-net-pdf-api/api/online/DS.Documents.Pdf/GrapeCity.Documents.Pdf.Structure.StructElement.html) class.
2. Add the structure element to the document's logical structure, represented by [StructTreeRoot](/document-solutions/dot-net-pdf-api/api/online/DS.Documents.Pdf/GrapeCity.Documents.Pdf.Structure.StructTreeRoot.html) class, using the Add method.
3. Create paragraph elements using the **StructElement** class and add it to the Part element.
4. Mark the beginning and end of the tagged content using [BeginMarkedContent](/document-solutions/dot-net-pdf-api/api/online/DS.Documents.Pdf/GrapeCity.Documents.Pdf.GcPdfGraphics.BeginMarkedContent.html) and [EndMarkedContent](/document-solutions/dot-net-pdf-api/api/online/DS.Documents.Pdf/GrapeCity.Documents.Pdf.GcPdfGraphics.EndMarkedContent.html) methods of the [GcPdfGraphics](/document-solutions/dot-net-pdf-api/api/online/DS.Documents.Pdf/GrapeCity.Documents.Pdf.GcPdfGraphics.html) class respectively.
5. Add content item to the paragraph element.
6. Mark the document as tagged using [MarkInfo.Marked](/document-solutions/dot-net-pdf-api/api/online/DS.Documents.Pdf/GrapeCity.Documents.Pdf.Structure.MarkInfo.Marked.html) property.
7. Save the tagged PDF using [Save](/document-solutions/dot-net-pdf-api/api/online/DS.Documents.Pdf/GrapeCity.Documents.Pdf.GcPdfDocument.Save.html) method of the [GcPdfDocument](/document-solutions/dot-net-pdf-api/api/online/DS.Documents.Pdf/GrapeCity.Documents.Pdf.GcPdfDocument.html) class.

    ```csharp
    public void CreateTaggedPdf()
    {
        var doc = new GcPdfDocument();
        int pageCount = 5;
    
        // create Part element, it will contain P (paragraph) elements
        StructElement sePart = new StructElement("Part");
        doc.StructTreeRoot.Children.Add(sePart);
    
        // Add some pages, on each page add some paragraphs and tag them:
        for (int pageIndex = 0; pageIndex < pageCount; ++pageIndex)
        {
            // Add page:
            var page = doc.Pages.Add();
            var g = page.Graphics;
            const float margin = 36;
            const float dy = 18;
    
            // Add some paragraphs:
            int paraCount = 4;
            float y = margin;
            for (int i = 0; i < paraCount; ++i)
            {
                // Create paragraph element:
                StructElement seParagraph = new StructElement("P") { DefaultPage = page };
    
                // Add it to Part element:
                sePart.Children.Add(seParagraph);
    
                // Create text layout:
                var tl = g.CreateTextLayout();
                tl.DefaultFormat.Font = StandardFonts.Helvetica;
                tl.DefaultFormat.FontSize = 12;
                tl.Append(i+1 + " .Test the pdf for tags");
                tl.MaxWidth = page.Size.Width;
                tl.MarginLeft = tl.MarginRight = margin;
                tl.PerformLayout(true);
    
                // draw TextLayout within tagged content
                g.BeginMarkedContent(new TagMcid("P", i));
                g.DrawTextLayout(tl, new PointF(0, y));
                g.EndMarkedContent();
    
                y += tl.ContentHeight + dy;
    
                // add content item to paragraph StructElement
                seParagraph.ContentItems.Add(new McidContentItemLink(i));
            }
        }
    
        // mark as tagged
        doc.MarkInfo.Marked = true;
    
        //Save the document
        doc.Save("TaggedPdf.pdf");
    }
    ```

For more information about how to work with tagged PDF using DsPdf, see [DsPdf sample browser](https://developer.mescius.com/documents-api-pdf/demos/basics/annotations/annotations/code-cs).