Destinations.vb
'' 完毕:
Imports System.IO
Imports System.Drawing
Imports System.Numerics
Imports GrapeCity.Documents.Pdf
Imports GrapeCity.Documents.Text
Imports GrapeCity.Documents.Drawing
Imports GrapeCity.Documents.Pdf.Annotations
Imports GrapeCity.Documents.Pdf.Actions
'' 演示如何创建目的地并将其与
'' 概述文档正文中的节点或链接。
Public Class Destinations
Function CreatePDF(ByVal stream As Stream) As Integer
Dim doc = New GcPdfDocument()
Dim page0 = doc.NewPage()
Dim page1 = doc.NewPage()
Dim page2 = doc.NewPage()
Dim mainNote = Util.AddNote(
"这是第 1 页。" + vbLf + vbLf + vbLf +
"",
page0)
Util.AddNote(
"这是第 2 页。",
page1)
Dim noteOnPage2 = Util.AddNote(
"第 2 页的注释 2。",
page1, New RectangleF(300, 400, 200, 300))
Util.AddNote(
"这是第 3 页",
page2)
Dim noteOnPage3 = Util.AddNote(
"这是第 3 页上的较长" + vbLf + "(尽管不是很长)" + vbLf + "注释。",
page2, New RectangleF(200, 440, 200, 300))
'' 大纲树中的目的地:
'' DestinationFit:适合整个页面:
Dim on1 = New OutlineNode("Page 1", New DestinationFit(page0))
doc.Outlines.Add(on1)
Dim on2 = New OutlineNode("Page 2", New DestinationFit(page1))
doc.Outlines.Add(on2)
'' DestinationXYZ:允许您指定顶部/左侧坐标和缩放级别(1 表示 100%):
on2.Children.Add(New OutlineNode("Note 2, zoom 200%", New DestinationXYZ(page1, noteOnPage2.X, noteOnPage2.Y, 2)))
on2.Children.Add(New OutlineNode("Zoom 100%", New DestinationXYZ(page1, Nothing, Nothing, 1)))
'' 添加返回第 1 页的链接:
on2.Children.Add(New OutlineNode("Back to page 1", New DestinationFit(page0)))
Dim on3 = New OutlineNode("Page 3", New DestinationFit(page2))
doc.Outlines.Add(on3)
'' DestinationFitR:适合页面上的矩形:
on3.Children.Add(New OutlineNode("Zoom to note on page 3", New DestinationFitR(page2, noteOnPage3)))
'' 添加返回第 1 页和第 2 页的链接:
on3.Children.Add(New OutlineNode("Go to page 2", New DestinationFit(page1)))
on3.Children.Add(New OutlineNode("Go to page 1", New DestinationFit(page0)))
'' 文档正文中的目标(重用大纲中的目标):
'' 转到第 2 页:
Dim rc = Util.AddNote("Go to page 2", page0, New RectangleF(72, mainNote.Bottom + 18, 200, 72))
page0.Annotations.Add(New LinkAnnotation(rc, on2.Dest))
'' 转到第 3 页:
rc = Util.AddNote("Go to page 3", page0, New RectangleF(72, rc.Bottom + 18, 200, 72))
page0.Annotations.Add(New LinkAnnotation(rc, on3.Dest))
'' 还可以命名目标并将其添加到文档的 NamedDestinations 字典中。
doc.NamedDestinations.Add("page1", New DestinationFit(page0))
doc.NamedDestinations.Add("page2", New DestinationFit(page1))
doc.NamedDestinations.Add("page3", New DestinationFit(page2))
'' 然后可以使用 DestinationRef 类引用它们,这里我们将它们添加到大纲中:
Dim onNamed = New OutlineNode("Named destinations", CType(Nothing, DestinationBase))
doc.Outlines.Add(onNamed)
onNamed.Children.Add(New OutlineNode("Named: page1", New DestinationRef("page1")))
onNamed.Children.Add(New OutlineNode("Named: page2", New DestinationRef("page2")))
onNamed.Children.Add(New OutlineNode("Named: page3", New DestinationRef("page3")))
''
'' 完毕:
doc.Save(stream)
Return doc.Pages.Count
End Function
End Class