I have two PDFs (A+B) and want to generate a new one which takes the first 2 pages of A then adds the first 2 pages of B, continues with p3-4 from A then p3-4 from B, then p5-6 from each, etc.
Any idea for a nice #hack with #FreeSoftware tools (preferable command line)?
@kirschner As always, ImageMagick can do it!
Here's a little hack https://src.jayvii.de/Hobby/Snippets/src/branch/main/merge_pdfs.sh
./merge_pdfs.sh 1.pdf 2.pdf 10
would execute:
/usr/bin/convert 1.pdf[1,2] 2.pdf[1,2] 1.pdf[3,4] 2.pdf[3,4] 1.pdf[5,6] 2.pdf[5,6] 1.pdf[7,8] 2.pdf[7,8] 1.pdf[9,10] 2.pdf[9,10] out.pdf
I suppose, this is what you were looking for?
That script is not very flexible, but rather specific to your task. Maybe you can build upon this :)
@kirschner @JayVii_de just a warning, iirc, ImageMagick can have strange results if the PDF isn't simply a container of raster images.
@resist1984 @kirschner
i haven't noticed any issues so far, but this concern does sound valid...
mupdftools should be able to achieve something similar and is more PDF specific than ImageMagick. Maybe it would have been a good idea to use that one instead.