'' 完毕:
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
'' 此示例演示如何创建标记(结构化)PDF。
'' 要查看/探索标签,请在 Adobe Acrobat Pro 中打开文档并转到
'' 查看 |导航面板|标签。
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)
'' 创建 Part 元素,它将包含 P(段落)元素
Dim sePart = New StructElement("Part")
doc.StructTreeRoot.Children.Add(sePart)
'' 添加一些页面,在每个页面上添加一些段落并标记它们:
For pageIndex = 0 To pageCount - 1
'' 添加页面:
Dim page = doc.Pages.Add()
Dim g = page.Graphics
Const margin = 36.0F
Const dy = 18.0F
'' 添加一些段落:
Dim paraCount = rnd.Next(1, 5)
Dim y = margin
For i = 0 To paraCount - 1
'' 创建段落元素:
Dim seParagraph = New StructElement("P") With {.DefaultPage = page}
'' 将其添加到 Part 元素:
sePart.Children.Add(seParagraph)
'' 创建段落:
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)
'' 在标记内容中绘制 TextLayout:
g.BeginMarkedContent(New TagMcid("P", i))
g.DrawTextLayout(tl, New PointF(0, y))
g.EndMarkedContent()
y += tl.ContentHeight + dy
'' 将内容项添加到段落 StructElement:
seParagraph.ContentItems.Add(New McidContentItemLink(i))
Next
Next
'' 将文档标记为已标记:
doc.MarkInfo.Marked = True
''
'' 完毕:
doc.Save(stream)
Return doc.Pages.Count
End Function
End Class