What are fast and reliable ways for converting a PDF into a (single) JPEG using the command line on Linux?
Linux: Install ImageMagick (on Ubuntu: sudo apt-get install imagemagick ) and then in a terminal type: convert [Input PDF File. pdf] [Output PNG File. png] . Mac OS X: Open the PDF in Preview and in the Save As dialog, set the filetype to png.
Linux users can use a command line utility called pdftotext — which is part of the poppler tools package — to convert PDFs to plain text format. Replace the input. pdf with the file you want to convert and the output. txt with the name you want attached to the newly created text file.
When the PDF file is successfully imported, go to the "File" tab and choose "Export To" from the drop-down list. Under the "Export To" drop-down menu, select the "Image" format to access a list of supported image formats. Locate and select the "PNG” option from the list.
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):
$ 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:
pdftoppm -jpeg -r 300 input.pdf output
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
[Produces ~2MB-sized files per pg] Output in .jpg format at highest 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
See the references below for more details and options.
Keywords: ubuntu linux convert pdf to images; pdf to jpeg; ptdf to tiff; pdf2images; pdf2tiff; pdftoppm; pdftoimages; pdftotiff; pdftopng; pdf2png
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With