Score:-1

Extract Pages from Various PDF Files into New PDF File

in flag

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?

kab00m avatar
br flag
Consider using pdftk, it does exactly what you want.
Arnaud Valmary avatar
in flag
Do you try poppler utils like `pdfseparate` and `pdfunite` ?
Score:1
in flag

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
in flag
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.
in flag
I attempted to rephrase the question, and I added my answer here: https://serverfault.com/questions/1141265
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.