In this tutorial, we will show you how to convert PDF files to image on Linux. Sometimes we need quickly convert a PDF file into images or save a set of images as a PDF file. To do this, we can use a couple of command-line tools such as poppler-utils and ImageMagick.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo
‘ to the commands to get root privileges. I will show you through the step-by-step convert PDF files to images on Linux.
Prerequisites
- A server running one of the following operating systems: Ubuntu Linux.
- It’s recommended that you use a fresh OS install to prevent any potential issues.
- A
non-root sudo user
or access to theroot user
. We recommend acting as anon-root sudo user
, however, as you can harm your system if you’re not careful when acting as the root.
Convert Pdf File To Image on Linux
Method 1. Convert PDF file via ImageMagick.
First, install ImageMagick on the Linux system. The installation of ImageMagick on the Ubuntu system is a rather simple process. From your terminal window execute the following command:
sudo apt install imagemagick
Use the command given below to convert all the images into a pdf file:
convert my-file.pdf output_image.png
Note: if you’re facing that PDF file conversions are not authorized by policy. You can fix it by executing the following command:
sed -i '/disable ghostscript format types/,+6d' /etc/ImageMagick-6/policy.xml
Method 2. Convert PDF file via Pdftoppm.
First, install Pdftoppm on your Linux system. To install poppler-utils
, we need to execute the following command below:
sudo apt install poppler-utils
Following is the basic syntax of the pdftoppm command:
pdftoppm -jpeg sample.pdf output_file
For example:
pdftoppm convert-PDF-to-images.pdf convert-PDF-to-images-png
To see all the choices available and supported in pdftoppm, run the commands:
pdftoppm --help
Congratulations! You have successfully converted the PDF file to an image. For more information about the convert PDF file to an image in Linux. For additional help or useful information, we recommend you check the official Pdftoppm website.