Sometimes you may not need the entire PDF, but just specific pages saved as separate files. Instead of uploading sensitive documents to third-party services, you can use the pdfseparate tool from the Poppler utilities. This tutorial explains how to extract pages from PDF file using Poppler pdfseparate.
Prepare environment
Ensure that the Poppler utilities are available on the machine. If you are using Ubuntu, you can follow the installation guide.
Extracting pages from PDF
First, download a sample PDF document for testing:
curl -sSo test.pdf https://raw.githubusercontent.com/py-pdf/sample-files/master/004-pdflatex-4-pages/pdflatex-4-pages.pdf
Now, use the pdfseparate
command to break the document into separate one-page PDFs:
pdfseparate test.pdf test-%d.pdf
This command creates new files, one for each page:
test-1.pdf test-2.pdf test-3.pdf test-4.pdf
Extracting specific page range
We don't need to split the entire file - we can specify a page range using -f
(first page) and -l
(last page). For instance, to extract only pages 2 through 4:
pdfseparate -f 2 -l 4 test.pdf test-%d.pdf
Result:
test-2.pdf test-3.pdf test-4.pdf
Leave a Comment
Cancel reply