TagParagraphs.vb
'' '' This code is part of Document Solutions for PDF demos. '' Copyright (c) MESCIUS inc. All rights reserved. '' Imports System.IO Imports System.Drawing Imports GrapeCity.Documents.Pdf Imports GrapeCity.Documents.Text Imports GrapeCity.Documents.Drawing Imports GrapeCity.Documents.Pdf.Structure Imports GrapeCity.Documents.Pdf.MarkedContent '' 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. Public Class TagParagraphs Function CreatePDF(ByVal stream As Stream) As Integer Dim doc = New GcPdfDocument() Dim rnd = Util.NewRandom() Dim pageCount = rnd.Next(3, 7) '' Create Part element, it will contain P (paragraph) elements Dim sePart = New StructElement("Part") doc.StructTreeRoot.Children.Add(sePart) '' Add some pages, on each page add some paragraphs and tag them: For pageIndex = 0 To pageCount - 1 '' Add page: Dim page = doc.Pages.Add() Dim g = page.Graphics Const margin = 36.0F Const dy = 18.0F '' Add some paragraphs: Dim paraCount = rnd.Next(1, 5) Dim y = margin For i = 0 To paraCount - 1 '' Create paragraph element: Dim seParagraph = New StructElement("P") With {.DefaultPage = page} '' Add it to Part element: sePart.Children.Add(seParagraph) '' Create paragraph: Dim tl = g.CreateTextLayout() tl.DefaultFormat.Font = StandardFonts.Helvetica tl.DefaultFormat.FontSize = 12 tl.Append(Util.LoremIpsum(1, 1, 5, 5, 10)) tl.MaxWidth = page.Size.Width tl.MarginLeft = margin 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)) Next Next '' Mark document as tagged: doc.MarkInfo.Marked = True '' '' Done: doc.Save(stream) Return doc.Pages.Count End Function End Class