You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, first off, thanks for this great library, it's very useful.
I am using the code bellow (based on this link) to attach files to a pdf. Everything works fine and the main desktop viewers (e.g. Adobe, Evince, Okular, etc) display the attachment icon correctly.
Unfortunately when viewing the same file using Firefox pdf viewer the icon does not appear (but the attached file is still present):
Investigating the problem I found this issue in the Firefox git. From what I could understand (I am far from a pdf specialist), the Firefox viewer assumes pdf files follow the 2.0 standard, where every annotation must have an associated appearance stream and the default icons (Graph, PushPin, Paperclip and Tag) do not exist.
As the pdf files I am creating will be mostly viewed on browsers, my question is if is possible to include an appearance stream in the pdf for the annotation icons using pikepdf (maybe copying from another file). I tried using generate_appearance_streams and get_appearance_stream but could not make it work.
Original file (no attachments): test.pdf
Attachment (just a random file): README.md
Output (annotation icon shows on the desktop viewers but not in the browser): test2.pdf
Example of a file where the annotation icon shows on the desktop viewers and in the browser: example.pdf
Thank you very much.
from pikepdf import Pdf, AttachedFileSpec, Name, Dictionary, Array
from pathlib import Path
pdf = Pdf.open('test.pdf')
filespec = AttachedFileSpec.from_filepath(
pdf,
Path('README.md'),
description='This is the file description')
# https://www.pdftron.com/api/PDFTronSDK/dotnet/pdftron.PDF.Annots.FileAttachment.html
# Note that FileAttachment icons can differ in their appearance dimensions,
# so you may want to match these Rectangle dimensions or the aspect ratio
# to avoid a squished or stretched appearance :
# e_Graph : 40 x 40 e_PushPin : 28 x 40 e_Paperclip : 14 x 34 e_Tag : 40 x 32
icons = {'Graph': (40, 40),
'PushPin': (28, 40),
'Paperclip': (14, 34),
'Tag': (40, 32)}
icon_name = 'PushPin'
xsize, ysize = icons[icon_name]
xmin = 100
xmax = xmin + xsize * 3
ymin = 700
ymax = ymin + ysize * 3
pushpin = Dictionary(Type=Name('/Annot'),
Subtype=Name('/FileAttachment'),
Name=Name(f'/{icon_name}'), # Name.PushPin,
FS=filespec.obj,
Rect=[xmin, ymin, xmax, ymax],
Contents='This is the file description',
C=(1.0, 1.0, 0.0), # color
T='Author',
M='D:20210101000000', # modification date
)
pdf.pages[0].Annots = pdf.make_indirect(Array([pushpin]))
pdf.save('test2.pdf')
The text was updated successfully, but these errors were encountered:
Hello, first off, thanks for this great library, it's very useful.
I am using the code bellow (based on this link) to attach files to a pdf. Everything works fine and the main desktop viewers (e.g. Adobe, Evince, Okular, etc) display the attachment icon correctly.
Unfortunately when viewing the same file using Firefox pdf viewer the icon does not appear (but the attached file is still present):
Investigating the problem I found this issue in the Firefox git. From what I could understand (I am far from a pdf specialist), the Firefox viewer assumes pdf files follow the 2.0 standard, where every annotation must have an associated appearance stream and the default icons (Graph, PushPin, Paperclip and Tag) do not exist.
As the pdf files I am creating will be mostly viewed on browsers, my question is if is possible to include an appearance stream in the pdf for the annotation icons using pikepdf (maybe copying from another file). I tried using
generate_appearance_streams
andget_appearance_stream
but could not make it work.Original file (no attachments): test.pdf
Attachment (just a random file): README.md
Output (annotation icon shows on the desktop viewers but not in the browser): test2.pdf
Example of a file where the annotation icon shows on the desktop viewers and in the browser: example.pdf
Thank you very much.
The text was updated successfully, but these errors were encountered: