Dave
Dave

Reputation: 19090

How do I replace a page in a PDF with another page using Ghostscript?

I'm using Ghostscript 9.21 on Mac High Sierra ...

localhost:~ davea$ gs -version
GPL Ghostscript 9.21 (2017-03-16)
Copyright (C) 2017 Artifex Software, Inc.  All rights reserved.

I have a PDF document with 4 pages. I would like to replace page 3 with another PDF file, pg3.pdf, consisting of one page. How do I do that using Ghostscript?

Upvotes: 2

Views: 1189

Answers (2)

AxeTB
AxeTB

Reputation: 21

I wanted to achieve this in one go instead of having to create separate pdf files first. Here is what worked for me and may be helpful to someone:

gs -sDEVICE=pdfwrite -sOutputFile=final.pdf -dBATCH -dNOPAUSE -sPageList=1-2 yourPdfFile.pdf -sPageList=1 newPdfPage.pdf -sPageList=4 yourPdfFile.pdf

Upvotes: 1

dkmrsa
dkmrsa

Reputation: 53

This should get the job done:

//get the first two pages

gs -sDEVICE=pdfwrite -sOutputFile=part1.pdf -dBATCH -dNOPAUSE -sPageList=1,2 yourPDFFile.pdf

//get the rest of the file

gs -sDEVICE=pdfwrite -sOutputFile=part2.pdf -dBATCH -dNOPAUSE -sPageList=4- yourPDFFile.pdf

//Merge files into one pdf

gs -sDEVICE=pdfwrite -sOutputFile=merge.pdf -dBATCH -dNOPAUSE part1.pdf pg3.pdf part2.pdf

Upvotes: 0

Related Questions