//// 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.Annotations;usingDsPdfWeb.Demos.Common; namespaceDsPdfWeb.Demos.Basics{// Demonstrates how to create destinations and associate them with// outline nodes or links in the document body.publicclassDestinations {publicintCreatePDF(Stream stream) {var doc = newGcPdfDocument(); var page0 = doc.NewPage();var page1 = doc.NewPage();var page2 = doc.NewPage(); var mainNote = Util.AddNote("This is page 1.\n\n\n" +"Demo of various destination types.\n\n" +"Destinations attached to nodes in the document's outline tree:\n" +" - Page 1: goes to this page, fits whole page\n" +" - Page 2: goes to page 2, fits whole page\n" +" -- Note 2, zoom 200%: goes to note 2 on page 2, zooms to 200%\n" +" -- Zoom 100%: zooms to whole page 2\n" +" -- Back to page 1: goes back to this page\n" +" - Page 3: goes to page 3, fits whole page\n" +" -- Zoom to note on page 3: zooms to whole note on page 3\n" +" -- Back to page 1: goes back to this page\n" +" - Named destinations: keyed by names in NamedDestinations dictionary:\n" +" -- page1\n" +" -- page2\n" +" -- page3\n\n" +"Destinations associated with areas in the document body:", page0);Util.AddNote("This is page 2.", page1);var noteOnPage2 = Util.AddNote("Note 2 on page 2.", page1, newRectangleF(300, 400, 200, 300));Util.AddNote("This is page 3", page2);var noteOnPage3 = Util.AddNote("This is a somewhat longer\n(even though not really long)\nnote on page 3.", page2, newRectangleF(200, 440, 200, 300)); // Destinations in the outline tree: // DestinationFit: fits whole page:var on1 = newOutlineNode("Page 1", newDestinationFit(page0)); doc.Outlines.Add(on1); var on2 = newOutlineNode("Page 2", newDestinationFit(page1)); doc.Outlines.Add(on2);// DestinationXYZ: allows specifying top/left coordinates and the zoom level (1 is 100%): on2.Children.Add(newOutlineNode("Note 2, zoom 200%", newDestinationXYZ(page1, noteOnPage2.X, noteOnPage2.Y, 2))); on2.Children.Add(newOutlineNode("Zoom 100%", newDestinationXYZ(page1, null, null, 1)));// Add a link back to page 1: on2.Children.Add(newOutlineNode("Back to page 1", newDestinationFit(page0))); var on3 = newOutlineNode("Page 3", newDestinationFit(page2)); doc.Outlines.Add(on3);// DestinationFitR: fits a rectangle on page: on3.Children.Add(newOutlineNode("Zoom to note on page 3", newDestinationFitR(2, noteOnPage3)));// Add links back to page 1 & 2: on3.Children.Add(newOutlineNode("Go to page 2", newDestinationFit(page1))); on3.Children.Add(newOutlineNode("Go to page 1", newDestinationFit(page0))); // Destinations in the document body (reusing destinations from the outlines):// Go to page 2:var rc = Util.AddNote("Go to page 2", page0, newRectangleF(72, mainNote.Bottom + 18, 200, 72)); page0.Annotations.Add(newLinkAnnotation(rc, on2.Dest));// Go to page 3: rc = Util.AddNote("Go to page 3", page0, newRectangleF(72, rc.Bottom + 18, 200, 72)); page0.Annotations.Add(newLinkAnnotation(rc, on3.Dest)); // Destinations can also be named and added to the document's NamedDestinations dictionary. doc.NamedDestinations.Add("page1", newDestinationFit(page0)); doc.NamedDestinations.Add("page2", newDestinationFit(page1)); doc.NamedDestinations.Add("page3", newDestinationFit(page2));// Then they can be referenced using DestinationRef class, here we add them to the outline:var onNamed = newOutlineNode("Named destinations", (DestinationBase)null); doc.Outlines.Add(onNamed); onNamed.Children.Add(newOutlineNode("Named: page1", newDestinationRef("page1"))); onNamed.Children.Add(newOutlineNode("Named: page2", newDestinationRef("page2"))); onNamed.Children.Add(newOutlineNode("Named: page3", newDestinationRef("page3"))); // Done: doc.Save(stream);return doc.Pages.Count; } }}