I have several documents (PDF, source available), some of which have an odd number of pages. I'd like to merge them (no problem so far with pdftk) and make sure that each document begins on a new piece of paper even when using duplex mode for printing.

The duplexing should be disabled for each last page of a sub-document with odd pages.

How is this possible?


Just insert a blank page after each document with an odd number of pages. Assuming that you have a PDF consisting of a single blank page named /path/to/blank.pdf, the following will do it automatically.

pdftk $(for i in *.pdf; do echo $i; pdftk $i dump_data | perl -ne 'print "/path/to/blank.pdf\n" if (m/NumberOfPages: (\d+)/ && $1 % 2 == 1)'; done) cat output merged.pdf
  • I thought of something like this myself, thanks for the exact script. There is however the problem of blank pages without duplex... – Jasper May 29 at 9:25
  • I must have read your question too fast. Do you mean you would like a single document that will print differently depending on whether it is sent to a duplexing printer? – notautogenerated May 29 at 9:54
  • That would be the perfect solution, but I fear that this is impossible. I'm fine with two versions of the bundled file. – Jasper May 29 at 13:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.