Loading...
X

How to convert PDF to JPG using command line in Linux (SOLVED)

PDF files are not very easy to split into image files in most programs that are used to open these files. However, there are several command line utilities for this. This article will show you how to convert PDF to JPEG on the Linux command line.

ImageMagick (convert)

To convert PDF to individual image files, let's start with the ImageMagick utility.

On Debian, Linux Mint, Ubuntu, Kali Linux and their derivatives, you can install this package with this command:

sudo apt install imagemagick

On Arch Linux, Manjaro and their derivatives, to install, run the command:

sudo pacman -S imagemagick
# To support other formats such as JPEG (JPEG XL and JPEG2000), HEIF, DNG, SVG, WEBP, WMF, OpenRaster, OpenEXR, DJVU, install the following dependencies:
sudo pacman -S ghostscript libheif libjxl libraw librsvg libwebp libwmf libxml2 libzip ocl-icd openexr openexr openjpeg2 djvulibre pango

Use convert like this:

convert input.pdf output.jpg

For good quality use these options

convert -density 300 -quality 100 in.pdf out.jpg

If you encounter errors, then the following articles may help you:

pdftoppm (from the poppler package)

On Debian, Linux Mint, Ubuntu, Kali Linux and their derivatives, you can install this package with this command:

sudo apt install poppler-utils

On Arch Linux, Manjaro and their derivatives, to install, run the command:

sudo pacman -S poppler

The command format is the following:

pdftoppm -jpeg -r 300 input.pdf output

In this command:

  • -jpeg sets the output image format to JPG,
  • -r 300 sets output image resolution to 300 dpi,
  • output will be the prefix for all image pages that will be numbered and placed in your current directory you are working with.

However, in my opinion, the best way is to first use “mkdir -p images” to create the “images” directory, and then set the output to images/pg so that all output images with a pg file prefix in front of each of their numbers are neatly placed in just that created directory images.

So here are my favorite commands:

We create files with a size of ~1 MB per page. Output in .jpg format at 300 dpi:

mkdir -p images
pdftoppm -jpeg -r 300 mypdf.pdf images/pg

We create files with a size of ~2 MB per page. Output in .jpg format at maximum quality (least compression) and still at 300 dpi:

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

If you need more resolution, you can try 600 DPI:

mkdir -p images
pdftoppm -jpeg -r 600 mypdf.pdf images/pg

… or 1200 dpi:

mkdir -p images
pdftoppm -jpeg -r 1200 mypdf.pdf images/pg

To create a single file, run:

pdftoppm -singlefile -jpeg -r 300 input.pdf output

vips (from libvips package)

On Debian, Linux Mint, Ubuntu, Kali Linux and their derivatives, you can install this package with this command:

sudo apt install libvips-tools

On Arch Linux, Manjaro and their derivatives, to install, run the command:

sudo pacman -S libvips

libvips can quickly convert PDF → JPEG. This program is present in the standard repositories of most Linux distributions, for macos you can use homebrew, and the Windows binary can be downloaded from the libvips site.

This command will convert PDF to JPG with default resolution (72):

vips copy somefile.pdf somefile.jpg

You can use the dpi option to set a different rendering resolution, like so:

vips copy somefile.pdf[dpi=600] somefile.jpg

You can select specific pages:

vips copy somefile.pdf[dpi=600,page=12] somefile.jpg

Or render five pages, starting with the third, like this:

vips copy somefile.pdf[dpi=600,page=3,n=5] somefile.jpg

The documentation for pdfload has all the options.

Comparison of program speeds:

time -f %M:%e convert -density 300 r8.pdf[3] x.jpg
276220:2.17

time -f %M:%e pdftoppm -jpeg -r 300 -f 3 -l 3 r8.pdf x.jpg
91160:1.24

time -f %M:%e vips copy r8.pdf[page=3,dpi=300] x.jpg
149572:0.53

So libvips is about 4 times faster and requires half the memory, at least in this test.

Online service to convert PDF to JPG

If you are a Windows user, or you do not want to install new utilities and deal with the command line to convert PDF to JPG, then you can split PDF files into separate images on the page of the Online service for converting PDF to JPG: https://suip.biz/?act=convert-pdf-to-jpg

This online service supports both single-page and multi-page PDF files. In the case of converting a multi-page PDF document, the files with page pictures will be placed in an archive for convenience, which can be downloaded at a time, regardless of the number of JPG files.

See also: How to convert JPG to PDF


Leave Your Observation

Your email address will not be published.