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.
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:
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");
Full Code:
using Spire.Pdf; namespace Bookmarks { class Program { static void Main(string[] args) { 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"); } } }
Imports Spire.Pdf Namespace Bookmarks Class Program Private Shared Sub Main(args As String()) 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") End Sub End Class End Namespace