How to convert a PDF into JPG with command line in Linux? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.

Closed 3 years ago . The community reviewed whether to reopen this question 5 months ago and left it closed:
Original close reason(s) were not resolved

What are fast and reliable ways for converting a PDF into a (single) JPEG using the command line on Linux?

33.7k 26 26 gold badges 151 151 silver badges 175 175 bronze badges asked Mar 29, 2017 at 6:25 8,769 15 15 gold badges 76 76 silver badges 138 138 bronze badges

If you build xpdf from sources it comes with little utilities for things like pdftotext, pdftojpeg, and podftohtml. They might be distributed with some Linux distros but they don't seem to be in this Debian I'm using.

Commented Nov 29, 2020 at 16:24

Sorry, they're in poppler-utils. pdfdetach, pdffonts, pdfimages, pdfinfo, pdfseparate, pdfsig, pdftocairo, pdftohtml, pdftoppm, pdftops, pdftotext and pdfunite. Or build xpdf from sources, I'm pretty sure.

Commented Nov 29, 2020 at 18:40

4 Answers 4

For the life of me, over the last 5 years, I cannot get imagemagick to work consistently (if at all) for me, and I don't know why people continually recommend it again and again. I just googled how to convert a PDF to a JPEG today, found this answer, and tried convert , and it doesn't work at all for me:

Broken command (doesn't work for me):

# BROKEN cmd $ convert in.pdf out.jpg convert-im6.q16: not authorized `in.pdf' @ error/constitute.c/ReadImage/412. convert-im6.q16: no images defined `out.jpg' @ error/convert.c/ConvertImageCommand/3258. 

(Update 24 Feb. 2022: here is the fix for imagemagick so convert will work. See also my comment here, and my comments under this answer here. I still like pdftoppm , below, much better, however.)

Then, I remembered there was another tool I use and wrote about, so I googled "linux convert pdf to jpg Gabriel Staples", clicked the first hit, and scrolled down to my answer. Here's what works perfectly for me. This is the basic command format:

Good command--use this instead:

# GOOD cmd pdftoppm -jpeg -r 300 input.pdf output 

Note: on Linux Ubuntu, you may need to do sudo apt update && sudo apt install poppler-utils in order to install pdftoppm . Thanks, @Reynadan.

The -jpeg sets the output image format to JPG, -r 300 sets the output image resolution to 300 DPI, and the word output will be the prefix to all pages of images, which will be numbered and placed into your current directory you are working in. A better way, in my opinion, however, is to use mkdir -p images first to create an "images" directory, then set the output to images/pg so that all output images will be placed cleanly into the images dir you just created, with the file prefix pg in front of each of their numbers.

Therefore, here are my favorite commands:

    [Produces ~1MB-sized files per pg] Output in .jpg format at 300 DPI:

mkdir -p images && pdftoppm -jpeg -r 300 mypdf.pdf images/pg 
mkdir -p images && pdftoppm -jpeg -jpegopt quality=100 -r 300 mypdf.pdf images/pg 
mkdir -p images && pdftoppm -jpeg -r 600 mypdf.pdf images/pg 
mkdir -p images && pdftoppm -jpeg -r 1200 mypdf.pdf images/pg 

See the references below for more details and options.

References:

  1. [my answer] Convert PDF to image with high resolution
  2. [my answer] https://askubuntu.com/questions/150100/extracting-embedded-images-from-a-pdf/1187844#1187844

Keywords: ubuntu linux convert pdf to images; pdf to jpeg; ptdf to tiff; pdf2images; pdf2tiff; pdftoppm; pdftoimages; pdftotiff; pdftopng; pdf2png