How can I programmatically delete a page from a PDF in Mac?

I have a bunch of PDF documents and they all contain the cover page that I want to delete.

Is there a way to programmatically delete them?

Most of the PDF utilities I found can combine documents but not delete pages. In the print dialog, I can select page 2 and then print the file, but I cannot find a way to access this function programmatically.

+5
source share
3 answers

Use pdftk .

To delete page 8:

pdftk in.pdf cat 1-7 9-end output out.pdf
+7
source

For write only: you can also use Ghostscript:

gs \
  -o removed-page-1-from-input.pdf \
  -sDEVICE=pdfwrite \
  -dFirstPage=2 \
  /path/to/input.pdf

pdftk ( ).

, Ghostscript input.pdf, . . ( ), .

pdftk PDF .


Update

Ghostscript -dLastPage. -dFirstPage .

-sPageList. :

-sPageList="1, 5-10, 12-"

1, 5-10 12 . , , , .

Ghostscript ( ), PDF GS . :

gs \
  -o selected-pages.pdf \
  -sDEVICE=pdfwrite     \
  -dFirstPage=2         \
  -dLastPage=2          \
   in1.pdf              \
                        \
  -dFirstPage=10        \
  -dLastPage=15         \
   in1.pdf              \
                        \
  -dFirstPage=1         \
  -dLastPage=1          \
   in1.pdf              \
                        \
  -dFirstPage=4         \
  -dLastPage=6          \
   in2.pdf

. , , / ( ), PDF .

+3

-[PDFDocument removePageAtIndex:] , . , Preview.app , , .

0

All Articles