Skip to content

Add hide_icon option to file attachment annotations - #1924

Open
ChrisJr404 wants to merge 1 commit into
py-pdf:masterfrom
ChrisJr404:hide-file-attachment-icon
Open

Add hide_icon option to file attachment annotations#1924
ChrisJr404 wants to merge 1 commit into
py-pdf:masterfrom
ChrisJr404:hide-file-attachment-icon

Conversation

@ChrisJr404

Copy link
Copy Markdown

This adds a hide_icon parameter to FPDF.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 /FS file 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:

  • A unit test is covering the code added / modified by this PR
  • In case of a new feature, docstrings have been added, with also some documentation in the docs/ folder
  • A mention of the change is present in CHANGELOG.md
  • This PR is ready to be merged

By submitting this pull request, I confirm that my contribution is made under the terms of the GNU LGPL 3.0 license.

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.
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