Skip to content

feat(api): chrome().viewerPreferences() — page mode / layout / window on open#243

Merged
DemchaAV merged 2 commits into
developfrom
feat/viewer-preferences
Jun 26, 2026
Merged

feat(api): chrome().viewerPreferences() — page mode / layout / window on open#243
DemchaAV merged 2 commits into
developfrom
feat/viewer-preferences

Conversation

@DemchaAV

Copy link
Copy Markdown
Owner

Why

A document couldn't say how a reader should present it on open — open the bookmark panel, use a two-column layout, show the title in the window. So a bookmarked document (the just-merged container bookmark(...), #242) still opened to a bare page with the outline hidden. This is the second half of G7.

What changed

  • chrome().viewerPreferences(DocumentViewerPreferences) writes page mode, page layout, and the window-chrome flags (displayDocTitle, hideToolbar, hideMenubar, fitWindow, centerWindow) to the PDF document catalog.
  • DocumentPageMode.USE_OUTLINES opens the bookmark panel — pairs with bookmark(...); DocumentViewerPreferences.openOutline() is a one-line preset. New enums DocumentPageMode / DocumentPageLayout (document.style).
  • Threaded through the existing chrome path (SessionChromeApiDocumentChromeOptionsDocumentOutputOptionsPdfOutputOptionsTranslatorPdfFixedLayoutBackendPdfDocumentPostProcessor) as a third document-global option alongside metadata and protection; the multi-section combined document takes it from the first section that sets it.
  • Advisory + PDF-only — other backends ignore it (the documented DocumentOutputOptions contract).

Lane: canonical API + chrome thread. Purely additive → japicmp-safe — the public apply(...) signatures are untouched (viewer prefs go through a new standalone applyViewerPreferences), and DocumentOutputOptions's new 5th component ships behind a re-declared 4-arg back-compat constructor.

Verification

  • ./mvnw test -pl .green, 0 changed visual baselines → a document that sets no viewer preferences never touches the catalog. ./mvnw -P japicmp verify — binary-compatible.
  • ViewerPreferencesTest (7) — asserts the catalog dictionary (not pixels, since viewer prefs are advisory): USE_OUTLINES page mode, two-column layout, the window flags incl. an explicit false still writing the /ViewerPreferences dict, page-mode-only writing no dict, no-preferences leaving the catalog at its defaults, and the multi-section first-section-wins rule. Enum mapping verified against PDFBox 3.0.7 (USE_THUMBNAILS → PageMode.USE_THUMBS).
  • A cold review confirmed byte-identity, japicmp, the enum mapping, and the anyFlag gate; it drove the multi-section + explicit-false + hideMenubar/centerWindow tests.
  • Runnable ViewerPreferencesExample + committed preview: a guide that opens with its bookmark panel showing (get_toc + catalog page mode UseOutlines verified).

With #242, this completes G7 (containers as outline targets + the reader opening straight to them).

DemchaAV added 2 commits June 26, 2026 10:41
…/ layout / window)

A document could not say how a reader should present it on open — open the
bookmark panel, use a two-column layout, show the title in the window — so a
bookmarked document still opened to a bare page with the outline hidden.

chrome().viewerPreferences(DocumentViewerPreferences) writes page mode, page
layout, and the window-chrome flags (displayDocTitle, hideToolbar, hideMenubar,
fitWindow, centerWindow) to the PDF document catalog. DocumentPageMode.USE_OUTLINES
opens the bookmark panel — it pairs with bookmark(...) on sections, and
DocumentViewerPreferences.openOutline() is a one-line preset. Threaded through the
existing chrome path (SessionChromeApi -> DocumentChromeOptions -> DocumentOutputOptions
-> translator -> backend -> post-processor) as a third document-global option
alongside metadata and protection; the multi-section combined document takes it from
the first section that sets it. Viewer preferences are advisory and PDF-only — other
backends ignore them, and a document that sets none does not touch the catalog, so
existing output is byte-for-byte unchanged.

Tests: ViewerPreferencesTest asserts the catalog dictionary (not pixels) — USE_OUTLINES
page mode, two-column layout, the window flags incl. an explicit false still writing the
/ViewerPreferences dict, page-mode-only writing no dict, no-preferences leaving the
catalog at its defaults, and the multi-section first-section-wins rule. Example:
ViewerPreferencesExample (a guide that opens with its bookmark panel).
The bookmark() that USE_OUTLINES opens the panel for now exists on container
flow builders (sections and containers), not only sections — widen the
openOutline() Javadoc accordingly.
@DemchaAV DemchaAV merged commit 30ff73d into develop Jun 26, 2026
11 checks passed
@DemchaAV DemchaAV deleted the feat/viewer-preferences branch June 26, 2026 09:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant