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

Stamps not copied when appending a page #1671

Closed
pubpub-zz opened this issue Feb 27, 2023 · 6 comments · Fixed by #1635
Closed

Stamps not copied when appending a page #1671

pubpub-zz opened this issue Feb 27, 2023 · 6 comments · Fixed by #1635
Labels
is-robustness-issue From a users perspective, this is about robustness workflow-annotation Everything about annotating PDF files

Comments

@pubpub-zz
Copy link
Collaborator

    > I recommend to use append() instead that add_page() that is pulling more data as you are copying the whole document this will be more simple:
from pypdf import PdfWriter

writer = PdfWriter()
writer.append('sample.pdf')
writer.write('new_sample.pdf')

Can you check you are getting what you are expecting ?

This approach works, however I still have the same result in the new file - the stamp annotation is not there.

Originally posted by @tiago719 in #1670 (comment)

@tiago719
Copy link

tiago719 commented Feb 28, 2023

Just to add more context, I am trying to iterates over the pages of a PDF file, removes specified annotations, and generates a new PDF file as output.
To simplify the example presented below, I have only included code for iterating over the pages and writing them to the new PDF
Upon opening the resulting "new_sample.pdf" file with Acrobat, it can be observed that the stamp annotation that existed in the original file has been unexpectedly removed.

from pypdf import PdfReader, PdfWriter

reader = PdfReader('sample.pdf')
writer = PdfWriter()
for page in reader.pages:
# Some operations that will change the page object
writer.add_page(page.get_object())

with open('new_sample.pdf', 'w+b') as f:
writer.write(f.name)

I tried implementing the changes suggested by @pubpub-zz:

from pypdf import PdfWriter

writer = PdfWriter()
writer.append('sample.pdf')
writer.write('new_sample.pdf')

But I got the same result - the stamp annotation is not in the new pdf file.
sample.pdf

@pubpub-zz pubpub-zz changed the title > I recommend to use append() instead that add_page() that is pulling more data as you are copying the whole document this will be more simple: Stamps not copied when appending a page Feb 28, 2023
@pubpub-zz
Copy link
Collaborator Author

@tiago719,
I've understood the problem : the "image" of the stamp file is stored in the names. working on a PR

@tiago719
Copy link

Thank you very much, that is great news!

@pubpub-zz
Copy link
Collaborator Author

@tiago719
I made a mistake in my analysis the issue was not because of Names correspondance but in some atttribute copy.
this is normally solved with #1635
Can you confirm my tests

@tiago719
Copy link

tiago719 commented Mar 1, 2023

Yap, that fixed the bug. Thanks

MartinThoma pushed a commit that referenced this issue Mar 5, 2023
* "/N" attributes wrongly ignored during copy process
* The object referenced via `src[field]` needs to be a dictionary

Fixes #1615, #1671
Fixes #1673
@MartinThoma
Copy link
Member

Closed by #1635

@MartinThoma MartinThoma added workflow-annotation Everything about annotating PDF files is-robustness-issue From a users perspective, this is about robustness labels Mar 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
is-robustness-issue From a users perspective, this is about robustness workflow-annotation Everything about annotating PDF files
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants