Add hide_icon option to file attachment annotations - #1924
Open
ChrisJr404 wants to merge 1 commit into
Open
Conversation
PDF viewers render a default icon (a paperclip, a pushpin, ...) for a file attachment annotation. Add a hide_icon parameter to FPDF.file_attachment_annotation() that gives the annotation an empty normal appearance stream, so conforming viewers draw no icon while the file stays embedded and reachable through the annotation. Cf. issue py-pdf#561.
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.
This adds a
hide_iconparameter toFPDF.file_attachment_annotation()so the default icon a viewer draws for an attachment (the paperclip, pushpin, etc.) can be suppressed while the file itself stays embedded and reachable, which is what was asked for in #561.The mechanism is the portable one from the PDF spec: when
hide_icon=True, the annotation gets an empty normal appearance stream (/AP << /N ... >>) pointing at a blank Form XObject. Conforming readers render the appearance stream instead of their built-in icon, and since it is empty, nothing is drawn. The/FSfile specification is untouched, so the attachment can still be opened or extracted from the annotation.The default is
False, so existing output is unchanged. I wired the appearance stream up at output time (once the XObject has an object id) next to where embedded files are added, and kept the mechanism generic on the annotation itself in case other annotation types want appearance streams later.Checklist:
docs/folderCHANGELOG.mdBy submitting this pull request, I confirm that my contribution is made under the terms of the GNU LGPL 3.0 license.