Support the UseAttachments page mode, and write /PageMode once (mirrors mpdf/mpdf#2142) - #17
Merged
Merged
Conversation
DisplayPreferences gains UseAttachments, which opens the reader's attachment pane on a document carrying embedded files. writeCatalog() had three independent places writing /PageMode — the outline pane implied by bookmarks, FullScreen from DisplayPreferences, and UseOC for the layer pane — so a document with bookmarks, layers and the pane open already emitted the key three times in one dictionary. A fourth mode would have made that worse, so the choice now happens in one place. The order preserves what readers resolve today, where the last write of a repeated key wins: UseOC, then FullScreen, then the new UseAttachments, and finally the outline pane, which is the only one the document never asked for explicitly. Mirrors mpdf#2142. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This mirrors mpdf#2142, so the fork carries the feature while the upstream PR sits open.
DisplayPreferencesgainsUseAttachments, which asks the reader to open its attachment pane — the counterpart toSetAssociatedFiles(), which already embeds the files but gives no way to say "show them".writeCatalog()had three separate places writing/PageMode: the outline pane implied by having bookmarks,FullScreenfromDisplayPreferences, andUseOCfor the layer pane. A document with bookmarks, layers andopen_layer_paneset already emitted the key three times in one dictionary, which a PDF dictionary cannot hold. Rather than add a fourth, the choice now happens once.Try it
The catalog carries
/PageMode /UseAttachments, and the reader opens with the attachment pane showing.Test plan
composer test— 1054 tests, 2541 assertions, green (gravitypdfis at 1048).composer cs— clean.gravitypdf, none new.tests/Mpdf/PageModeTest.php— three of its six cases fail ongravitypdf: the two for the new keyword, andtestLayerPaneWinsOverEverythingElse, which catches the existing duplicate-key bug.More info
Where it differs from upstream
/PageModewriter next to theFullScreenoneMetadataWriter::getPageMode()composer csrejects it)Precedence
Readers resolve a repeated dictionary key by taking the last one written, so the order below is the one documents get today, with the new keyword slotted in among the explicit requests:
UseOC—open_layer_panewith layers presentFullScreen—DisplayPreferencesUseAttachments—DisplayPreferencesUseOutlines— the only one the document never asks for; it follows from having any bookmark at allSo nothing that resolved to a given mode before resolves differently now.
PDF version
/PageMode /UseAttachmentsis PDF 1.6, andpdf_versiondefaults to1.4. That matches how/PrintScaling(1.6) and/Duplex(1.7) are already handled here — written with a comment noting the version, no header bump — so this follows suit rather than changing when mPDF advertises a higher version.Also touched
SetDisplayPreferences()carried a comment listing the accepted keywords that had drifted — noFullScreen, noNoPrintScaling. It now lists what the writer actually reads.