//// This code is part of Document Solutions for PDF .NET demos.// Copyright (c) MESCIUS inc. All rights reserved.//usingSystem.IO;usingSystem.Drawing;usingGrapeCity.Documents.Pdf;usingGrapeCity.Documents.Pdf.Structure;usingGrapeCity.Documents.Pdf.MarkedContent; namespaceDsPdfWeb.Demos.Basics{// This sample shows how to create tagged (structured) PDF.// To see/explore the tags, open the document in Adobe Acrobat Pro and go to// View | Navigation Panels | Tags.publicclassTagParagraphs {publicintCreatePDF(Stream stream) {var doc = newGcPdfDocument();var rnd = Common.Util.NewRandom();int pageCount = rnd.Next(3, 7); // Create Part element, it will contain P (paragraph) elementsvar sePart = newStructElement("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;constfloatmargin = 36;constfloatdy = 18; // Add some paragraphs:int paraCount = rnd.Next(1, 5);float y = margin;for (int i = 0; i < paraCount; ++i) {// Create paragraph element:var seParagraph = newStructElement("P") { DefaultPage = page };// Add it to Part element: sePart.Children.Add(seParagraph); // Create paragraph:var tl = g.CreateTextLayout(); tl.DefaultFormat.Font = StandardFonts.Helvetica; tl.DefaultFormat.FontSize = 12; tl.Append(Common.Util.LoremIpsum(1, 1, 5, 5, 10)); tl.MaxWidth = page.Size.Width; tl.MarginLeft = tl.MarginRight = margin; tl.PerformLayout(true); // Draw TextLayout within tagged content: g.BeginMarkedContent(newTagMcid("P", i)); g.DrawTextLayout(tl, newPointF(0, y)); g.EndMarkedContent(); y += tl.ContentHeight + dy; // Add content item to paragraph StructElement: seParagraph.ContentItems.Add(newMcidContentItemLink(i)); } } // Mark document as tagged: doc.MarkInfo.Marked = true; // Done: doc.Save(stream);return doc.Pages.Count; } }}