Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link in the new (3.14.0) annotation module returns an empty dict. #2058

Closed
ymareth opened this issue Aug 1, 2023 · 6 comments · Fixed by #2066
Closed

Link in the new (3.14.0) annotation module returns an empty dict. #2058

ymareth opened this issue Aug 1, 2023 · 6 comments · Fixed by #2066
Labels
is-bug From a users perspective, this is a bug - a violation of the expected behavior with a compliant PDF

Comments

@ymareth
Copy link

ymareth commented Aug 1, 2023

The new Link class in annotation returns an empty* dict and hence creates no link.
I took a look at the link class and can't see any calls to self.update (since the base class is dict) as I do in the other annotation classes.

I reverted back to pypdf.generic.AnnotationBuilder.add_link with the same call parameters and links are inserted as expected.

*possibly 'title' would get through via the kwargs into the super constructor.

Environment

Windows, Python 3.11, running version 3.14.0

@pubpub-zz
Copy link
Collaborator

@ymareth
can you please provide standalone test code

@MartinThoma MartinThoma added needs-pdf The issue needs a PDF file to show the problem needs-example-code The issue needs a minimal and complete (e.g. all imports) example showing the problem is-bug From a users perspective, this is a bug - a violation of the expected behavior with a compliant PDF and removed needs-pdf The issue needs a PDF file to show the problem labels Aug 2, 2023
@ymareth
Copy link
Author

ymareth commented Aug 4, 2023

For version 3.13.0 this produces a link:

from pypdf import PdfWriter
from pypdf.generic import AnnotationBuilder

writer = PdfWriter()
writer.add_blank_page(720, 720)
writer.write('test.pdf')

link_annotation = AnnotationBuilder.link(rect=(0, 00, 300, 300), target_page_index=1)
print(link_annotation)
writer.add_annotation(0, link_annotation)

writer.write('link1.pdf')

Results in what looks like a healthy link definition:

{'/Type': '/Annot', '/Subtype': '/Link', '/Rect': RectangleObject([50, 100, 150, 200]), '/Border': [0, 0, 0], '/Dest': {'target_page_index': 1, 'fit': '/Fit', ''fit_args': []}}

For version 3.14.0 we have to change the code a bit to use the annotations module:

import pypdf as pp
import pypdf.annotations as ppa

writer = pp.PdfWriter()
writer.add_blank_page(720, 720)
writer.write('test.pdf')

writer = pp.PdfWriter()
with open('test.pdf' , 'rb') as fh:
    reader = pp.PypdfReader(fh)
    writer.add_page(reader.pages[0])
    link = ppa.Link(rect=(50, 100, 150, 200), targer_page_index=1)
    print(link)

Results in and empty dict.

{}

@MartinThoma MartinThoma removed the needs-example-code The issue needs a minimal and complete (e.g. all imports) example showing the problem label Aug 6, 2023
@MartinThoma
Copy link
Member

Thank you for reporting the issue. I've adjusted the first code sample a bit and will have a look.

@MartinThoma
Copy link
Member

Found the issue. Fix is on its way.

MartinThoma added a commit that referenced this issue Aug 6, 2023
The object was not updating itself, but a temporary variable in it

Closes #2058
MartinThoma added a commit that referenced this issue Aug 6, 2023
The object was not updating itself, but a temporary variable in it

Closes #2058
@MartinThoma
Copy link
Member

Thank you for letting us know 🙏

The issue is fixed with pypdf==3.15.0

@MartinThoma
Copy link
Member

If you want, I can add you as a contributor: https://pypdf.readthedocs.io/en/latest/meta/CONTRIBUTORS.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
is-bug From a users perspective, this is a bug - a violation of the expected behavior with a compliant PDF
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants