How to merge 2 PDF files with interleaving pages order?

pdftk has a shuffle command which collates pages:

pdftk A=odd.pdf B=even.pdf shuffle A B output collated.pdf

See the pdfseparate and pdfunite commands from poppler-utils. The first to separate the pages from each document into individual files, and the second to merge them in the order you want in a new document.

Also note that since scanners give you raster images anyway (which some like yours can concatenate into a PDF files), maybe you can configure it to output images (png, tiff...) instead, and do the concatenation into a PDF yourself with ImageMagick.


Just a bash quick shot using pdfjam:

Build an array of input arguments:

for k in $(seq 1 ${N_PAGES}); do
    PAGES+=(odd.pdf);
    PAGES+=($k);
    PAGES+=(even.pdf);
    PAGES+=($k);
done

This should allow you to use it as input list for pdfjoin:

 pdfjoin ${PAGES[@]} --outfile shuffled.pdf

Tags:

Pdf

Printing