Destinations.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 System.Numerics
- Imports GrapeCity.Documents.Pdf
- Imports GrapeCity.Documents.Text
- Imports GrapeCity.Documents.Drawing
- Imports GrapeCity.Documents.Pdf.Annotations
- Imports GrapeCity.Documents.Pdf.Actions
-
- '' Demonstrates how to create destinations and associate them with
- '' outline nodes or links in the document body.
- 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(
- "This is page 1." + vbLf + vbLf + vbLf +
- "Demo of various destination types." + vbLf + vbLf +
- "Destinations attached to nodes in the document's outline tree:" + vbLf +
- " - Page 1: goes to this page, fits whole page" + vbLf +
- " - Page 2: goes to page 2, fits whole page" + vbLf +
- " -- Note 2, zoom 200%: goes to note 2 on page 2, zooms to 200%" + vbLf +
- " -- Zoom 100%: zooms to whole page 2" + vbLf +
- " -- Back to page 1: goes back to this page" + vbLf +
- " - Page 3: goes to page 3, fits whole page" + vbLf +
- " -- Zoom to note on page 3: zooms to whole note on page 3" + vbLf +
- " -- Back to page 1: goes back to this page" + vbLf +
- " - Named destinations: keyed by names in NamedDestinations dictionary:" + vbLf +
- " -- page1" + vbLf +
- " -- page2" + vbLf +
- " -- page3" + vbLf + vbLf +
- "Destinations associated with areas in the document body:",
- page0)
- Util.AddNote(
- "This is page 2.",
- page1)
- Dim noteOnPage2 = Util.AddNote(
- "Note 2 on page 2.",
- page1, New RectangleF(300, 400, 200, 300))
- Util.AddNote(
- "This is page 3",
- page2)
- Dim noteOnPage3 = Util.AddNote(
- "This is a somewhat longer" + vbLf + "(even though not really long)" + vbLf + "note on page 3.",
- page2, New RectangleF(200, 440, 200, 300))
-
- '' Destinations in the outline tree:
-
- '' DestinationFit: fits whole page:
- 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: allows specifying top/left coordinates and the zoom level (1 is 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)))
- '' Add a link back to page 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: fits a rectangle on page:
- on3.Children.Add(New OutlineNode("Zoom to note on page 3", New DestinationFitR(page2, noteOnPage3)))
- '' Add links back to page 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)))
-
- '' Destinations in the document body (reusing destinations from the outlines):
- '' Go to page 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))
- '' Go to page 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))
-
- '' Destinations can also be named and added to the document's NamedDestinations dictionary.
- doc.NamedDestinations.Add("page1", New DestinationFit(page0))
- doc.NamedDestinations.Add("page2", New DestinationFit(page1))
- doc.NamedDestinations.Add("page3", New DestinationFit(page2))
- '' Then they can be referenced using DestinationRef class, here we add them to the outline:
- 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")))
- ''
- '' Done:
- doc.Save(stream)
- Return doc.Pages.Count
- End Function
- End Class
-