How to Automatically Display Bookmarks or Thumbnails When PDF is Opened in C#, VB.NET

When a user opens a PDF document they see the initial view of the PDF. By default, the Bookmarks Panel or Thumbnails Panel is not shown when the PDF is opened. In this article, we're going to demonstrate how to set document properties so that the Bookmarks Panel or Thumbnails Panel will be open every time the file is launched.

Check the test file below, only the page content is showing when the document is opened.

How to Automatically Display Bookmarks or Thumbnails When PDF is Opened in C#, VB.NET

Code Snippet and Effect:

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

PdfDocument Pdf = new PdfDocument();
Pdf.LoadFromFile("Test.pdf");

Step 2: In the class of ViewerPreferences, there is a PageMode property that specifies how the document should be displayed when opened. Set PageMode as UseOutlines, save the changes to a new PDF file named "ShowBookmarks".

Pdf.ViewerPreferences.PageMode = PdfPageMode.UseOutlines;
Pdf.SaveToFile("ShowBookmarks.pdf");

Open the newly-generated file, Bookmarks Panel will be automatically displayed as below:

How to Automatically Display Bookmarks or Thumbnails When PDF is Opened in C#, VB.NET

Step 3: If we set PageMode as UseThumbs, and save the changes to another PDF file named "ShowThumbnails", then we will get following effect if we open this file.

Pdf.ViewerPreferences.PageMode = PdfPageMode.UseThumbs;
Pdf.SaveToFile("ShowThumbnails.pdf");

How to Automatically Display Bookmarks or Thumbnails When PDF is Opened in C#, VB.NET

Full Code:

[C#]
PdfDocument Pdf = new PdfDocument();
Pdf.LoadFromFile("Test.pdf");
Pdf.ViewerPreferences.PageMode = PdfPageMode.UseOutlines;
Pdf.SaveToFile("ShowBookmarks.pdf");
Pdf.ViewerPreferences.PageMode = PdfPageMode.UseThumbs;
Pdf.SaveToFile("ShowThumbnails.pdf");
[VB.NET]
Dim Pdf As New PdfDocument()
Pdf.LoadFromFile("Test.pdf")
Pdf.ViewerPreferences.PageMode = PdfPageMode.UseOutlines
Pdf.SaveToFile("ShowBookmarks.pdf")
Pdf.ViewerPreferences.PageMode = PdfPageMode.UseThumbs
Pdf.SaveToFile("ShowThumbnails.pdf")