pdfcpu / pdfcpu

A PDF processor written in Go.

Home Page:http://pdfcpu.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Multi stamping might skip last pages of the stamp PDF

vsenko opened this issue · comments

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.

Thanks for reporting this!

Fixed with latest commit!