-1

From

  • a.pdf, I would like pages 2 and 5
  • b.pdf, pages 3 and 4
  • c.pdf, pages 7, 8, and 9

copied into a new PDF file. All input pdf files are ten pages long. I'm using bash, and plan to make many documents like this (with different input files and different pages) over the coming years. What is the best way to do this?

1 Answers1

1

With poppler utils pdfseparate and pdfunite:

#! /usr/bin/env bash

input_filename_1="a.pdf"
input_filename_2="b.pdf"
input_filename_3="c.pdf"

output_filename="of.pdf"

pdfseparate -f 2 -l 2 "$input_filename_1" if_1_%03d.pdf 2>/dev/null
pdfseparate -f 5 -l 5 "$input_filename_1" if_1_%03d.pdf 2>/dev/null
pdfseparate -f 3 -l 4 "$input_filename_2" if_2_%03d.pdf 2>/dev/null
pdfseparate -f 7 -l 9 "$input_filename_3" if_3_%03d.pdf 2>/dev/null
ls -l if_*_*.pdf

pdfunite if_1_*.pdf if_2_*.pdf if_3_*.pdf "$output_filename" 2>/dev/null
ls -l "$output_filename"

rm -f if_*_*.pdf
  • Thank you for your answer. I created another solution based on pdftk (only one call to pdftk is required), but it looks like I can no longer answer this question because it was deemed off topic as a request for learning materials. – lmat - Reinstate Monica Aug 10 '23 at 23:47
  • I attempted to rephrase the question, and I added my answer here: https://serverfault.com/questions/1141265 – lmat - Reinstate Monica Aug 12 '23 at 01:02