I have found many related questions in this forum. But, none addresses my issue. Please double-check before marking it as duplicate.
Suppose I have two PDF files.
first.pdfhaving 10 pages.second.pdfhaving 20 pages.
I want to create a new PDF file, where I need pages - 2,5,6,9 from first.pdf and pages 6,7,15,19 from second.pdf.
How to do it from command line?
24 Answers
You can use pdfseparate command to split all pages of pdfs into single page pdf. The following command will create last_page-first_page pdfs where their name will be out_<pageNumber>:
pdfseparate -f <first_page> -l <last_page> <file_name>.pdf out_%d.pdfApply the process to both pdf using different output name for each input pdf, so you don't overwrite previously created single page pdfs. Then you can use pdfunite for merging selected pages into a single one pdf:
pdfunite <ordered list of pdf> <output_filename>.pdf 1 You can use pdftk
in just ONE step:
pdftk A=first.pdf B=second.pdf cat A2 A5 A6 A9 B6 B7 B15 B19 output final.pdfPS. If you need to install, you should:
sudo apt-get install pdftk Install pdftk:
sudo apt install pdftkthen, to extract "2 5 6 9" from first one in a file named "1.pdf":
pdftk first.pdf cat 2 5 6 9 output 1.pdfand for the second.pdf:
pdftk second.pdf cat 6 7 15 19 output 2.pdfThen merge them:
pdftk 1.pdf 2.pdf output final.pdfAnd remove unnecessary ones:
rm 1.pdf 2.pdf 3 As pdftk is no longer available in the repositories you could use mutool from mupdf-tools with a command like:
mutool merge -o output.pdf first.pdf 2,5,6,9 second.pdf 6,7,15,19