- How to merge multiple PDF files in Linux
- How to replace a single page in a PDF file using another PDF file in Linux
By using the PDF Toolkit PDFtk library you can do this simple pdf editing task and many more. For all of you creating software related to PDF documents you should really spend some time reading about PDFtk server.
apt install pdftk
In this example we have two pdf files with 10 pages each. The command below will keep the pages 1-9, add the first page of the second document and end the output file.
pdftk A=first.pdf B=second.pdf cat A1-9 B1-end output out.pdf
In case we need to add a page in between of other pages of the first document to our output document, for example to keep the first 1-5, add the 1 page of the second document, keep 6-10 of the first document and end the output document, we can use the command below.
pdftk A=first.pdf B=second.pdf cat A1-5 B1 A6-end output out.pdf