How to convert PDF ...
 
Notifications
Clear all

[Solved] How to convert PDF to JPG in Linux?

   RSS

0
Topic starter

I have a few PDF files that I need to convert into JPEG format, and I'm looking for a command-line tool that can help me do this in Linux. I've tried searching online, but most of the solutions I've found involve using ImageMagick, which isn't installed by default on my system.

Is there a simple way to convert PDF to JPEG using a tool that's already available on most Linux systems?

Thanks in advance for your help!

8 Answers
2

One tool that's often overlooked but typically comes installed on many Linux distributions is LibreOffice. LibreOffice can convert PDF files to various formats, including JPEG, via the command line without needing to open the GUI. Here's how you can do it:

  1. First, ensure LibreOffice is installed. It usually is, but if not, you can easily install it through your package manager.
  2. Use the LibreOffice command line as follows:
libreoffice --headless --convert-to jpg yourfile.pdf

This command converts your PDF into JPEG format, storing the output in the current directory. It's an excellent way to batch convert PDFs to JPEGs without installing additional software.

@quantumcat Love it! Thanks for the tip.

0

Have you considered using poppler-utils? It's commonly installed on many Linux distributions and includes a command called pdftoppm that can convert PDF files to image formats including JPEG. You can install it with your package manager, for example, sudo apt-get install poppler-utils on Debian-based systems. Once installed, you can convert a PDF to JPEG using:

pdftoppm -jpeg yourfile.pdf outputname

This command will convert each page of the PDF into a separate JPEG file. Hope this helps!

0

Another tool you might have on your Linux system is Ghostscript. It's a versatile tool that can handle PDF files among many other tasks. To convert a PDF to JPEG with Ghostscript, you can use the following command:

gs -dNOPAUSE -sDEVICE=jpeg -r300 -sOutputFile=outputname-%03d.jpg yourfile.pdf -c quit

This command will create a JPEG file for each page of the PDF, named outputname-001.jpg, outputname-002.jpg, etc., at 300 DPI. Check if Ghostscript is installed by typing gs --version. If it's not, you can usually install it via your distribution's package manager.

0

Consider using pdftocairo, a part of the poppler-utils package, to convert PDF to JPEG. It offers fine control over the conversion process, including specifying the DPI and the page range. If poppler-utils is not installed, it's worth installing it as it provides various tools for working with PDFs. To convert a PDF to JPEG using pdftocairo, you can run:

pdftocairo -jpeg -r 300 yourfile.pdf outputname

This command converts the PDF to a high-quality JPEG at 300 DPI.

0

Jumping back to pdftoppm, I want to highlight its versatility. You can adjust the output quality of your JPEGs by using the -jpegopt option. For instance:

pdftoppm -jpeg -jpegopt quality=90 yourfile.pdf outputname

This sets the JPEG quality to 90, balancing file size and image quality. It's a useful feature when you need to manage output file sizes.

0

I know you mentioned avoiding ImageMagick, but for completeness, if you decide to install ImageMagick, converting PDFs to JPEG is straightforward with the convert command:

convert -density 300 yourfile.pdf -quality 90 outputname.jpg

This command specifies both the density (DPI) and the quality of the output JPEG. ImageMagick is a powerful tool for image manipulation, and installing it could be beneficial for tasks beyond just converting PDFs.

0

If you're open to a scripting approach and have Python installed, PyMuPDF is a fantastic library for working with PDFs. You can install it via pip (pip install PyMuPDF) and use the following script to convert a PDF to JPEG:

import fitz # PyMuPDF 

pdf_file = "yourfile.pdf" 
doc = fitz.open(pdf_file) 

for page_num in range(len(doc)): 
page = doc.load_page(page_num) 
pix = page.get_pixmap() 
output = f"outputname-{page_num}.jpg" 
pix.save(output)

This Python script provides flexibility for batch processing and can be easily modified to adjust output quality or size.

@scriptguru Great idea! I will try this someday. Still learning scripting.

0

Why does it have to be so hard?

I convert it online: https://oneconvert.com/pdf-converter/pdf-to-jpg

It's free and easier than all those codes. 

Share: