How to replace a single page in a pdf using another pdf in linux?
I want to find out the easiest way to replace a single page in a multiple page PDF with another single page PDF in Linux. What tool is best for this?
Currently I do it like this:
- split pdf to single pages using pdfsam
- replace the pages that I want to replace
- merge them using pdfsam
- use ghostscript to force the page size as same
Any better way?
You could use the PDF Toolkit PDFtk:
Example:
pdftk A=inA.pdf B=inB.pdf cat A1-12 B3 A14-end output out1.pdf
The output consists of the first 12 pages of inA.pdf
, followed by page 3 of inB.pdf
and then pages 14 until end of inA.pdf
.
Many Linux distributions provide a PDFtk package you can download and install using their package manager.
You could also use qpdf which is open source:
Same example as the one in the other response:
qpdf --empty --pages inA.pdf 1-12 inB.pdf 3 inA.pdf 14-z -- out1.pdf
If you just wanted to replace the last page of a two-page pdf with another pdf (one-page), like me, but not trying to insert a page in between pages, it can be done like so:
sudo pdftk A=Doc1.pdf B=Doc2.pdf cat A1 B output DocEdited.pdf
Note:
- This will replace the last page in Doc1 with the page from Doc2;
- B is like B1-end; since Doc2 is a PDF of one page so B1 or B is the same;
- cat A1: Taking the first page from A (or Doc1).