César
César

Reputation: 162

Aspose XYZExplicitDestination.CreateDestination Bookmark doesn’t work for first one

I added a few bookmark to a pdf and it does work if I add with GoToAction but it doesn’t when I use XYZExplicitDestination (I want to use this to avoid zoom changes).

So this piece it works for all pages:

    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);

But this one does’t work for the first bookmarks:

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, 0, 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, 0, 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, 0, 0, 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);

Any idea why? It’s just the first parent and first child , the ones that don’t work.

The version I am using is 19.4.0.0. Also happening for latest one (21.3.0)

Upvotes: 0

Views: 296

Answers (1)

César
César

Reputation: 162

If we use pdfDocument.Pages[n].MediaBox.Height the problem is solved.

For more info:

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

Upvotes: 0

Related Questions