Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I've got a double-side-printed multipage document to scan with a linear bulk scanner. So, as the result I get 2 PDF files: one containing all odd pages and the second containing all even pages. I need to merge them the natural way:

1. <- 1.1. (odd.pdf page 1 to result.pdf page 1)
2. <- 2.1. (even.pdf page 1 to result.pdf page 2)
3. <- 1.2. (odd.pdf page 2 to result.pdf page 3)
4. <- 2.2. (even.pdf page 2 to result.pdf page 4)


share|improve this question
Just find a PDF parser and do a merge sort like stuff. –  warl0ck Oct 30 '12 at 10:00
Thanks, captain Obvious! :-] –  Ivan Oct 30 '12 at 10:02
If Stephane doesn't solve your problem, you can try the perl module CAM::PDF, I'll give your a script later. Does the two pdf have same page count? –  warl0ck Oct 30 '12 at 11:24

3 Answers 3

up vote 3 down vote accepted

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.

share|improve this answer
This sounds like what I need, let's try... –  Ivan Oct 30 '12 at 10:07
Indeed. Excellent. Simple to use to do right what I need. by the way, I have, of course, googled before asking and solutions I've found to exactly the same were notably more complex. –  Ivan Oct 30 '12 at 13:07

Just a bash quick shot using pdfjam:

Build an array of input arguments:

for k in $(seq 1 ${N_PAGES}); do

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

 pdfjoin ${PAGES[@]} --outfile shuffled.pdf
share|improve this answer
It should be noted that pdfjoin is a wrapper script around pdfjam which is itself a wrapper script around the pdfpages LaTeX package (and pdflatex) so it means that it brings LaTeX as a dependency. –  Stéphane Chazelas Oct 30 '12 at 14:11

pdftk has a shuffle command which collates pages:

pdftk A=even.pdf B=odd.pdf shuffle A B output collated.pdf
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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