gs -sDEVICE=pdfwrite -dFirstPage=2 -dLastPage=5 -o output.pdf input.pdf

Category: Media & Conversion

gs -sDEVICE=pdfwrite -dFirstPage=2 -dLastPage=5 -o output.pdf input.pdf

Extract a page range to a new PDF

Copies pages 2 through 5 into a new PDF. -dFirstPage and -dLastPage bound the range, and gs processes only those pages. Combined with -o for clean batch behavior. A single page uses -dFirstPage=1 -dLastPage=1.
Looking for more? Search all 7,657 commands — works offline, in English or Spanish, and fixes typos.