Converting a PDF to JPG from the command line comes down to three solid tools: Poppler's pdftoppm, ImageMagick, and Ghostscript. Each gives you different control over output resolution and page selection. This guide gives you the exact commands, explains what every flag does, and shows you how to fix the ImageMagick security-policy error that stops most Linux users on their first attempt. Prefer not to install anything? The online tool at pdftojpgconverter.net handles it with a standard DPI and JPEG compression set to a high quality.
Using Poppler Pdftoppm
Poppler's pdftoppm is the straightforward one. It outputs one image per page, numbered sequentially.
Basic Command
The syntax:
pdftoppm -jpeg -r 300 input.pdf outThis creates out-1.jpg, out-2.jpg, and so on. The -jpeg flag sets JPEG output. The -r flag sets resolution in DPI. Omit -r and you get a standard DPI. For sharp results, use a higher DPI.
Selecting Specific Pages
Grab a page range with -f for the first page and -l for the last:
pdftoppm -jpeg -r 300 -f 3 -l 5 input.pdf outThat converts only pages 3 through 5.
Outputting PNG Instead
Need PNG? Swap -jpeg for -png. All other flags work identically.
pdftoppm -png -r 300 input.pdf outUsing ImageMagick
ImageMagick version 7 uses the magick command. It hands the actual PDF rendering off to Ghostscript, so Ghostscript must be on your system.
Basic Command
Run it like this:
magick -density 300 input.pdf out.jpgThe -density flag sets output resolution in DPI. Put it before the input file. If you place -density after, the page renders at low resolution first, and then the density setting gets applied to an already degraded image. The result looks soft.
Common Error: Security Policy
On Linux, you may hit this:
attempt to perform an operation not allowed by the security policy `PDF'A PDF rule in ImageMagick's policy.xml file causes it. Many distributions ship with PDF handling locked down. Fix it by editing policy.xml. Look for it at /etc/ImageMagick-7/policy.xml or /usr/local/etc/ImageMagick-7/policy.xml. Find the line that reads and either remove it or comment it out. Save the file and the command runs.
Using Ghostscript Directly
Ghostscript converts PDF to JPG without leaning on ImageMagick. It is faster and hands you direct control over JPEG compression.
Basic Command
The command:
gs -sDEVICE=jpeg -r300 -dJPEGQ=90 -o page-%03d.jpg input.pdfWhat each flag does:
- -sDEVICE=jpeg tells Ghostscript to output JPEG.
- -r300 sets 300 DPI.
- -dJPEGQ=90 sets the compression level. The scale runs from low to high. Higher numbers mean larger files and finer detail.
- -o page-%03d.jpg defines the output filename pattern. %03d produces three-digit page numbers with leading zeros: page-001.jpg, page-002.jpg.
Ghostscript processes every page by default. To limit the range, add -dFirstPage=3 -dLastPage=5 before the input file.
Batch Convert PDF to JPG Script
Got a folder full of PDFs? A short shell script handles them in one go. Here is the pdftoppm version:
for pdf in *.pdf; do pdftoppm -jpeg -r 300 "$pdf" "${pdf%.pdf}"doneThis loops through every PDF in the current directory. For each one it creates a set of JPG images sharing the PDF's base name. A file called report.pdf becomes report-1.jpg, report-2.jpg.
To batch convert with Ghostscript, use a similar loop:
for pdf in *.pdf; do gs -sDEVICE=jpeg -r300 -dJPEGQ=90 -o "${pdf%.pdf}-%03d.jpg" "$pdf"doneBoth scripts quote the variables, so filenames with spaces work.
When to Use Each Tool
Pick the one that fits your situation:
- pdftoppm is the simplest. Use it for basic conversion with page selection. It ships inside Poppler, which comes preinstalled on most Linux systems.
- ImageMagick gives you image-processing options after conversion. It needs Ghostscript underneath and often needs that security-policy edit on Linux.
- Ghostscript puts JPEG compression in your hands directly. It is the engine driving many other tools. Fast and dependable.
If installing software or editing config files sounds like friction you do not need right now, pdftojpgconverter.net does the job in a browser. It uses a standard DPI and JPEG compression set to a high quality.