Get PDF Viewer Preferences

Contents
[ ]

Aspose.PDF provides tools to access and update PDF viewer preferences. These preferences define the initial layout and presentation behavior of a PDF document in PDF readers. This includes options such as enabling outline view, hiding menu bars, or specifying page layout modes. Using PdfContentEditor, you can retrieve existing preferences, check specific flags, and update them as needed.

  1. Define ViewerPreference Flags.
  2. Initialize PdfContentEditor and Bind PDF.
  3. Get Current Viewer Preferences.
  4. Check Specific Flags.
  5. Display Current Preferences.
import aspose.pdf.facades as pdf_facades
import sys
from enum import IntFlag
from os import path

sys.path.append(path.join(path.dirname(__file__), ".."))

from config import set_license, initialize_data_dir


def get_viewer_preferences(infile):
    # Create PdfContentEditor object
    content_editor = pdf_facades.PdfContentEditor()
    # Bind document to PdfContentEditor
    content_editor.bind_pdf(infile)
    # Read current viewer preference flags
    viewer_preference = ViewerPreference(content_editor.get_viewer_preference())
    if viewer_preference & ViewerPreference.PAGE_MODE_USE_OUTLINES:
        print("PageModeUseOutlines is enabled")
    print(f"Current viewer preference: {viewer_preference}")