How to Convert PDF to JPG on Linux Using the Terminal
Linux users have access to some of the most powerful PDF-to-JPG conversion tools available — all free, all open-source, and all controllable from the command line. Unlike GUI tools that hide settings behind menus, terminal commands give you precise control over DPI, quality, color space, page selection, and batch processing. This guide covers the three main tools Linux users rely on: pdftoppm (part of the poppler-utils package), Ghostscript, and ImageMagick. Each has different strengths — pdftoppm is fastest for bulk extraction, Ghostscript gives the most color-accurate output, and ImageMagick provides the richest post-processing options. We also cover Python scripting for automated workflows. All commands in this guide work on Ubuntu, Debian, Fedora, Arch, and any mainstream Linux distribution. Package names may vary slightly between distributions, but the commands themselves are identical.
Using pdftoppm for Fast, High-Quality Conversion
pdftoppm is part of the poppler-utils package and is often the fastest tool for converting PDF pages to images. It uses libpoppler, the same rendering engine behind many PDF viewers, and produces excellent quality output. Install on Ubuntu/Debian: `sudo apt install poppler-utils` Install on Fedora: `sudo dnf install poppler-utils` Install on Arch: `sudo pacman -S poppler` pdftoppm outputs PPM format by default, but it supports JPEG output via the `-jpeg` flag. Use `-jpegopt quality=90` to set JPEG quality, and `-r 300` to set resolution in DPI.
- 1Install poppler-utils: `sudo apt install poppler-utils` (Ubuntu/Debian)
- 2Basic conversion at 150 dpi: `pdftoppm -jpeg -r 150 input.pdf output`
- 3High-quality 300 dpi: `pdftoppm -jpeg -jpegopt quality=90 -r 300 input.pdf output`
- 4Convert a single page (page 3): `pdftoppm -jpeg -r 300 -f 3 -l 3 input.pdf page3`
- 5Convert pages 1–5: `pdftoppm -jpeg -r 300 -f 1 -l 5 input.pdf pages`
- 6Files are named output-01.jpg, output-02.jpg, etc. automatically
Using Ghostscript for Maximum Quality Control
Ghostscript is the oldest and most capable PDF processing engine on Linux. It offers the most control over output quality, color space, and compression parameters. Install on Ubuntu/Debian: `sudo apt install ghostscript` Install on Fedora: `sudo dnf install ghostscript` Basic command for single-page JPG output: `gs -dNOPAUSE -dBATCH -sDEVICE=jpeg -r300 -dJPEGQ=90 -sOutputFile=page%d.jpg input.pdf` Key parameters explained: - `-sDEVICE=jpeg` — JPEG output (use `jpeg` for standard, `jpeg_cmyk` for CMYK) - `-r300` — 300 DPI resolution (use 150 for screen, 600 for archival) - `-dJPEGQ=90` — JPEG quality 0–100 (85–95 recommended) - `-sOutputFile=page%d.jpg` — output filename with auto-numbering - `-dFirstPage=2 -dLastPage=5` — process pages 2 through 5 only For RGB color accuracy (important for photography): add `-sColorConversionStrategy=RGB` For highest quality with minimal compression: `-dJPEGQ=95 -r600` Ghostscript batch processing all PDFs in a folder: `for f in *.pdf; do gs -dNOPAUSE -dBATCH -sDEVICE=jpeg -r300 -dJPEGQ=90 -sOutputFile="${f%.pdf}_%d.jpg" "$f"; done`
Using ImageMagick with Ghostscript Backend
ImageMagick's `convert` command provides a user-friendly interface for PDF conversion and excellent post-processing capabilities. Note: ImageMagick requires Ghostscript installed for PDF support. Install: `sudo apt install imagemagick ghostscript` IMPORTANT — ImageMagick 6 has a security policy that blocks PDF conversion by default. Edit `/etc/ImageMagick-6/policy.xml` and change the PDF policy line: From: `<policy domain="coder" rights="none" pattern="PDF" />` To: `<policy domain="coder" rights="read|write" pattern="PDF" />` Basic conversion: `convert -density 300 -quality 90 input.pdf output.jpg` Convert with explicit color space: `convert -density 300 -quality 90 -colorspace RGB input.pdf output.jpg` Convert a single page (zero-indexed — page 0 is page 1): `convert -density 300 -quality 90 input.pdf[0] page1.jpg` Batch convert all PDFs in a folder: `for f in *.pdf; do convert -density 300 -quality 90 "$f" "${f%.pdf}_%d.jpg"; done` Resize while converting (useful for thumbnails): `convert -density 300 -quality 90 -resize 800x1100 input.pdf output.jpg`
Python Automation with PyMuPDF (fitz)
For automated workflows — processing batches of PDFs, integrating PDF-to-JPG in scripts, or building document processing pipelines — Python with PyMuPDF (also called fitz) is the most powerful approach. Install: `pip install pymupdf` Basic Python script to convert all pages of a PDF to JPG: ```python import fitz # PyMuPDF doc = fitz.open('input.pdf') for page_num in range(len(doc)): page = doc[page_num] mat = fitz.Matrix(300/72, 300/72) # 300 DPI pix = page.get_pixmap(matrix=mat) pix.save(f'page_{page_num + 1}.jpg') doc.close() ``` Adjusting quality — PyMuPDF uses JPEG quality via the `jpg_quality` parameter: ```python pix.save(f'page_{page_num + 1}.jpg', jpg_quality=90) ``` Batch processing all PDFs in a directory: ```python import fitz, glob, os for pdf_path in glob.glob('*.pdf'): doc = fitz.open(pdf_path) base = os.path.splitext(pdf_path)[0] for i, page in enumerate(doc): mat = fitz.Matrix(300/72, 300/72) pix = page.get_pixmap(matrix=mat) pix.save(f'{base}_page{i+1}.jpg', jpg_quality=90) doc.close() ``` PyMuPDF is significantly faster than calling external tools via subprocess and produces excellent quality output.
Frequently Asked Questions
What is the fastest way to convert PDF to JPG on Linux?
pdftoppm is generally the fastest tool for bulk PDF-to-JPG conversion on Linux. It uses the poppler rendering engine optimized for throughput. For a 50-page PDF at 300 dpi, pdftoppm typically completes in 10–30 seconds, faster than equivalent Ghostscript or ImageMagick commands. Install with `sudo apt install poppler-utils` and run `pdftoppm -jpeg -r 300 input.pdf output`.
Why does ImageMagick say 'attempt to perform an operation not allowed by the security policy'?
ImageMagick has a security policy that blocks PDF operations by default to prevent a historical security vulnerability. Edit `/etc/ImageMagick-6/policy.xml` (or `/etc/ImageMagick-7/policy.xml` for ImageMagick 7) and change the PDF policy line from `rights="none"` to `rights="read|write"`. Save the file and retry your convert command.
How do I convert only specific pages of a PDF to JPG on Linux?
With pdftoppm: use `-f` (first page) and `-l` (last page) flags — e.g., `pdftoppm -jpeg -f 3 -l 5 input.pdf output` converts pages 3–5. With Ghostscript: use `-dFirstPage=3 -dLastPage=5` in your gs command. With ImageMagick: use bracket notation — `convert input.pdf[2-4] output.jpg` converts pages 3–5 (zero-indexed). With PyMuPDF: slice the document — `for page in doc[2:5]` processes pages 3–5.
Which Linux tool gives the best JPG quality — Ghostscript, pdftoppm, or ImageMagick?
All three use similar underlying rendering capabilities, and at the same DPI and quality settings, output quality is nearly identical for standard documents. For photographs embedded in PDFs, Ghostscript with explicit `-sColorConversionStrategy=RGB` provides the most accurate color reproduction. pdftoppm tends to produce the best quality-to-speed ratio for mixed documents. ImageMagick's advantage is rich post-processing options (resize, sharpen, adjust) in the same command.