Aspose XYZExplicitDestination.CreateDestination 书签不适用于第一个

问题描述

我在 pdf 中添加了一些书签,如果我使用 GoToAction 添加它确实有效,但是当我使用 XYZExplicitDestination 时它不起作用(我想用它来避免缩放更改)。

所以这篇文章适用于所有页面

    string dataDir = "C:\\Whatever";

    // Open document
    Document pdfDocument = new Document(dataDir + "filename.pdf");

    // Create a parent bookmark object
    OutlineItemCollection pdfOutline = new OutlineItemCollection(pdfDocument.Outlines);
    pdfOutline.Action = new GoToAction(pdfDocument.Pages[1]);
    pdfOutline.Title = "Parent Bookmark - Page 1";

    // Create a child bookmark object
    OutlineItemCollection pdfChildOutline = new OutlineItemCollection(pdfDocument.Outlines);
    pdfChildOutline.Title = "Child Outline - Page 1";
    pdfChildOutline.Action = new GoToAction(pdfDocument.Pages[1]);

    OutlineItemCollection pdfChildOutline3 = new OutlineItemCollection(pdfDocument.Outlines);
    pdfChildOutline3.Title = "Child Outline page 3";
    pdfChildOutline3.Action = new GoToAction(pdfDocument.Pages[3]);

    // Add child bookmark in parent bookmark's collection
    pdfOutline.Add(pdfChildOutline);
    pdfOutline.Add(pdfChildOutline3);

    // Add parent bookmark in the document's outline collection.
    pdfDocument.Outlines.Add(pdfOutline);

    dataDir = dataDir + "AddChildBookmark_out.pdf";
    // Save output
    pdfDocument.Save(dataDir);

但这对第一个书签不起作用:

string dataDir = "C:\Whatever";

    // Open document
    Document pdfDocument = new Document(dataDir + "Filename.pdf");

    // Create a parent bookmark object
    OutlineItemCollection pdfOutline = new OutlineItemCollection(pdfDocument.Outlines);
    pdfOutline.Destination = new XYZExplicitDestination(0,1); //Sets the inherit zoom for the bookmarks for contents
    pdfOutline.Title = "Parent Bookmark - Page 1";

    // Create a child bookmark object
    OutlineItemCollection pdfChildOutline = new OutlineItemCollection(pdfDocument.Outlines);
    pdfChildOutline.Title = "Child Outline - Page 1";
    pdfChildOutline.Destination = new XYZExplicitDestination(0,1); //Sets the inherit zoom for the bookmarks for contents

    OutlineItemCollection pdfChildOutline3 = new OutlineItemCollection(pdfDocument.Outlines);
    pdfChildOutline3.Title = "Child Outline page 3";
    pdfChildOutline3.Destination = new XYZExplicitDestination(2,1); //Sets the inherit zoom for the bookmarks for contents


    // Add child bookmark in parent bookmark's collection
    pdfOutline.Add(pdfChildOutline);
    pdfOutline.Add(pdfChildOutline3);

    // Add parent bookmark in the document's outline collection.
    pdfDocument.Outlines.Add(pdfOutline);

    dataDir = dataDir + "AddChildBookmark_out.pdf";
    // Save output
    pdfDocument.Save(dataDir);

知道为什么吗?这只是第一个父母和第一个孩子,那些不起作用。

我使用的版本是 19.4.0.0。最新的 (21.3.0) 也发生了

解决方法

如果我们使用 pdfDocument.Pages[n].MediaBox.Height 问题就解决了。

更多信息:

https://forum.aspose.com/t/aspose-pdf-19-4-0-0-bookmark-doesnt-work-for-first-bookmark-net/227998