Destinations.cs
// 完毕:
using System;
using System.IO;
using System.Drawing;
using GrapeCity.Documents.Pdf;
using GrapeCity.Documents.Text;
using GrapeCity.Documents.Drawing;
using GrapeCity.Documents.Pdf.Annotations;
using GrapeCity.Documents.Pdf.Actions;
using DsPdfWeb.Demos.Common;

namespace DsPdfWeb.Demos.Basics
{
    // 演示如何创建目的地并将其与
    // 概述文档正文中的节点或链接。
    public class Destinations
    {
        public int CreatePDF(Stream stream)
        {
            var doc = new GcPdfDocument();

            var page0 = doc.NewPage();
            var page1 = doc.NewPage();
            var page2 = doc.NewPage();

            var mainNote = Util.AddNote(
                "这是第 1 页。\n\n\n" +
                "",
                page0);
            Util.AddNote(
                "这是第 2 页。",
                page1);
            var noteOnPage2 = Util.AddNote(
                "第 2 页的注释 2。",
                page1, new RectangleF(300, 400, 200, 300));
            Util.AddNote(
                "这是第 3 页",
                page2);
            var noteOnPage3 = Util.AddNote(
                "这是第 3 页上的较长\n(尽管不是很长)\n注释。",
                page2, new RectangleF(200, 440, 200, 300));

            // 大纲树中的目的地:

            // DestinationFit:适合整个页面:
            var on1 = new OutlineNode("Page 1", new DestinationFit(page0));
            doc.Outlines.Add(on1);

            var 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, null, null, 1)));
            // 添加返回第 1 页的链接:
            on2.Children.Add(new OutlineNode("Back to page 1", new DestinationFit(page0)));

            var 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(2, 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 页:
            var 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 类引用它们,这里我们将它们添加到大纲中:
            var onNamed = new OutlineNode("Named destinations", (DestinationBase)null);
            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;
        }
    }
}