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

Multi stamping might skip last pages of the stamp PDF #814

Closed
vsenko opened this issue Feb 29, 2024 · 2 comments
Closed

Multi stamping might skip last pages of the stamp PDF #814

vsenko opened this issue Feb 29, 2024 · 2 comments
Assignees

Comments

@vsenko
Copy link

vsenko commented Feb 29, 2024

There is a problem with the new multi stamping feature introduced in v0.6.0: it can skip several last pages of the stamp PDF file.

For example: pdfcpu stamp add -mode pdf -- "stamp.pdf:1:2" "" in.pdf out.pdf

In case if in.pdf is 5 pages and stamp.pdf is 2 pages, then in the output pages 2-5 will be stamped with page 1 of stamp.pdf. While the expected out.pdf should have page 2 stamped with page 1 of stamp.pdf and pages 3-5 stamped with page 2 of stamp.pdf.

Here goes an example:

Looks like the problem is here: maxStampPageNr := wm.PdfMultiStartPageNrSrc + len(wm.PdfRes) - 1 (https://github.com/pdfcpu/pdfcpu/blob/master/pkg/pdfcpu/stamp.go#L1022)

In our test case 1 + 2 - 1 = 2, thus only pages 1 and 2 skip the test on the next line (pageNr > maxStampPageNr), that is why pages 3-4 get the same stamp as page 2.

It seems to me that the correct one would be maxStampPageNr := wm.PdfMultiStartPageNrDest + len(wm.PdfRes) - 1.

@hhrutter
Copy link
Collaborator

Thanks for reporting this!

@hhrutter
Copy link
Collaborator

hhrutter commented Mar 2, 2024

Fixed with latest commit!

vsenko added a commit to vsenko/pdfcpu that referenced this issue Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants