Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use ghostscript to delete a page (not extracting a range)

I know ghostscript can use -dfirstpage -dlastpage to only make a file from a range of pages, but I need to make it (or another command line program) delete the 2nd page in any pdf where the range of pages is not explicitly told. I thought this would be far easier because most printers let you specify "1,3-end" and I have been using PDFCreator to do it that way.

The one way I can think of doing it (very very messy) is to extract page 1, extract pages 3 to end, and then merge the two pdfs. But I also don't know how to have GS determine the number of pages.

like image 801
extispex Avatar asked Feb 14 '23 07:02

extispex


1 Answers

Use the right tool for the job!

For reasons outlined by KenS, Ghostscript is not the best tool for what you want to achieve. A better tool for this task is pdftk. To remove the 2nd page from input.pdf, you should run this command line:

pdftk  input.pdf  cat 1 3-end  output output.pdf
like image 176
Kurt Pfeifle Avatar answered Feb 15 '23 20:02

Kurt Pfeifle