-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?

2
  • Consider using pdftk, it does exactly what you want.
    – kab00m
    Commented Aug 9, 2023 at 21:45
  • Do you try poppler utils like pdfseparate and pdfunite ? Commented Aug 10, 2023 at 11:04

1 Answer 1

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
2
  • 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. Commented Aug 10, 2023 at 23:47
  • I attempted to rephrase the question, and I added my answer here: serverfault.com/questions/1141265 Commented Aug 12, 2023 at 1:02

Not the answer you're looking for? Browse other questions tagged .