How to replace a single page in a pdf using another pdf in linux?

46

19

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:

  1. split pdf to single pages using pdfsam
  2. replace the pages that I want to replace
  3. merge them using pdfsam
  4. use ghostscript to force the page size as same

Any better way?

xgdgsc

Posted 2013-06-24T03:01:56.093

Reputation: 976

Answers

71

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.

Axel Kemper

Posted 2013-06-24T03:01:56.093

Reputation: 2 892

6Thanks! Note, A= and B= must be uppercase. When I tried lowercase pdftk though a= was part of the filename. – biscuit314 – 2017-10-09T13:23:31.937

7

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

Guillaume S-RIMBAULT

Posted 2013-06-24T03:01:56.093

Reputation: 71

You probably mean inB.pdf instead of B.pdf. This should probably be the accepted answer as pdftk is discontinued as far as I know. – Marius Hofert – 2019-04-09T10:40:24.497

I don't know if you can change the accepted answer after it is already set. However, I agree this is the better option as it is still very actively maintained. I also really like the fact that it offers an AppImage so you can use it without installing. :D – Michael Tunnell – 2019-05-13T15:42:03.253