rrthomas / pdfjam

The pdfjam package for manipulating PDF files
GNU General Public License v2.0
378 stars 28 forks source link

Requested functionality: step and repeat #61

Closed DinizCabreira closed 8 hours ago

DinizCabreira commented 1 year ago

Hello,

Maybe I am missing the options to do it, but I've been browsing the documentations and examples for a while, and I can't figure it out.

I'd like to be able to output two copies of a PDF's pages, side by side, into a new, 2x sized document. Ideally, I'd be able to tell the script 2x1 or 1x2, and it'd calculate the output page size as necessary.

Please notice that I don't want page1+page2, page3+page4... in the same sheet of paper, but page1+page1, page2+page2...

I believe this action is typically called «step and repeat» in some PDF manipulation tools, so maybe (if the functionality is missing) adding a --step NxM switch to pdfjam would be a good approach.

If this is possible with the current PDFjam options -- could you please direct me to documentation, or instruct me on how to do it?

mgkurtz commented 2 days ago

Hey @DinizCabreira, thanks for your suggestion, this is indeed a somewhat common wish. Luckily this is already possible by combining pdfjam with other tools.

To get each page twice, generate 1,1,2,2,3,3,…,$n,$n as a page specification for pdfjam. Below this is done with python, but whichever way you like is fine.

f=a.pdf
n=$(pdfinfo "$f"|awk '/^Pages:/{sub(/^Pages: */,"");print}')
pdfjam --nup 2x1 --landscape "$f" $(python3 -c "print(','.join([str(i+1) for i in range($n) for _ in range(2)]))")

Sticking to Unix philosophy, this solution is fine and I would not add a specific option (and feature creep) to pdfjam.

To ease such plumbing, pdfjam could however be improved to accept page specifications separated by white space, or allow trailing commas. Then you could use some fun as seq 1 $(pdfpages a.pdf) | cat -n in place of the python code. Having pdfinfo return only the relevant information would be nice as well.

mgkurtz commented 8 hours ago

Hah, you never stop learning: pdfpages already provides the option duplicatepages. Hence, all you need to do is

pdfjam --landscape --nup 2x1 --duplicatepages 2 a.pdf