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 and EndMarkedContent methods.
To create a tagged PDF:
C# |
Copy Code
|
---|---|
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.