Set inherit zoom property for PDF bookmarks

By using Acrobat, we can edit the PDF bookmark actions and set the zoom level to "Inherit Zoom". Then no matter which bookmark you click, the PDF page will stay the same size as the previous page you are viewing and it won't be changed. Spire.PDF also enables developers to set the Bookmark actions to inherit zoom by setting PdfDestination.Zoom as 0. This article will show you how to update bookmarks in a PDF document in C#.

Firstly, view the original screenshot of the PDF bookmark property:

How to set inherit zoom property for PDF bookmarks

Here comes to the step of how to use Spire.PDF to set the PDF bookmark actions.

Step 1: Create a new PDF document and load the document from file.

PdfDocument pdfdoc = new PdfDocument();
pdfdoc.LoadFromFile("TheGreatGatsby.pdf");

Step 2: Get bookmarks collections of the PDF file.

PdfBookmarkCollection bookmarks = pdfdoc.Bookmarks;

Step 3: Set Zoom level as 0, which the value is inherit zoom.

foreach (PdfBookmark bookMark in bookmarks)
 {
   //value 1 is the actual size, other value is the customized size.
   bookMark.Destination.Zoom =0;                              
 }

Step 4: Save the document to file.

pdfdoc.SaveToFile("result.pdf");

Effective screenshot after setting the zoom level to Inherit zoom.

How to set inherit zoom property for PDF bookmarks

Full codes:

using Spire.Pdf;
using Spire.Pdf.Bookmarks;


namespace SetInheritZoomProperty
{
    class Program
    {
        static void Main(string[] args)
        {

            PdfDocument pdfdoc = new PdfDocument();
            pdfdoc.LoadFromFile("TheGreatGatsby.pdf");

            PdfBookmarkCollection bookmarks = pdfdoc.Bookmarks;

            foreach (PdfBookmark bookMark in bookmarks)
            {
                bookMark.Destination.Zoom = 0;

            }

            pdfdoc.SaveToFile("result.pdf");
        }
    }
}