Top

PDFelement - Edit, Annotate, Fill and Sign PDF Documents

appstore
Get from App Store

Get

PDFelement - Read, Annotate and Sign PDF

appstore
Get it on Google Play

Get

How to Convert PDF to Image using PHP

2021-11-29 13:52:29 • Filed to: Knowledge of PDF • Proven solutions

There are scores of people out there tirelessly seeking how to convert PDF to image in php. If you are one of them, then your prayer is answered. In this article, we shall give you a detailed guide on how to convert PDF to image using php with and without ImageMagick.

How to Convert PDF to Image using PHP with ImageMagick

ImageMagick software provides a platform to create bitmap images and is PHP in-built. The following steps illustrate how you can convert PDF to image using PHP with ImageMagick.

Step 1: Open the PHP coding environment and start by creating imagic object using the code.

$imagick = new Imagick();

Step 2: Now read the image from the target PDF file using the code:

$imagick->readImage('myfile.pdf');

Step 3: To convert all your PDF pages to PNG format for example, simply run the following code.

$imagick->writeImages('converted.png', false);

Notice that the writeImages() code returns false as the second parameter. This ensures that it will create separate images for each page.

If you want to only convert a specific page of your PDF file to PNG, for example, just pass an index on the PDF name, as shown below. "test.pdf [0]" will convert the first page alone.

php pdf to image

To convert a specific PDF page with desired quality, simply add $imagick->setResolution (150, 150). This code should appear before the program loads or create the image.

In case a transparency issue arises when you convert your PDF to png, try whether flattening can work as illustrated in the code below.

$imagick = $imagick->flattenImages();

pdf to image php


How to Convert PDF to Image using PHP without ImageMagick

Users can convert PDF to image using PHP without necessarily with ImageMagick.

Step 1. Open the PHP coding environment. To load the target source PDF file, write the code "$source=" myFile.pdf";

Step 2. Now choose the desired output image file by writing the code "$target= "converted.png";

Step 3. Execute your conversion by running the code:

exec('/usr/local/bin/convert "'.$source .'" -colorspace RGB –res

However, you should change the location of the binaries to the right location of your server. This location can be obtained from the hosting admin.

Step 4. You can now print the response once the PDF is successfully converted to png using the echo command.

Close the php code.

convert pdf to image using php without imagemagick


How to Convert PDF to Image without PHP

PDFelement is a comprehensive PDF tool that lets users convert PDF files to almost all file formats, including image formats. The program has plenty of useful features that make it suitable to handle all kinds of work, including professional works. If you want to convert single or multiple PDF files at once, then PDFelement will be a great tool. Being a total no-brainer tool, it suits all categories of users. Again, it is compatible with almost all operating systems and devices, and therefore there is no need to worry about what device you are using. Other features include:

  • Protect PDF with passwords and redaction features.
  • Share PDF files as email attachments.
  • Create forms both manually and automatically.
  • Approve client's documents digitally via digital signatures.
  • Combine several PDF files to form a single large PDF file.
  • Add comments to PDF contents.
  • Open secured and other PDFs using a variety of ways.
  • Add bookmarks, snapshots, and attachments o your PDFs.
  • Edit links, objects, and texts on your PDF file.
  • Shrink your PDF file without affecting the original quality.
  • Perform OCR to make scanned PDFs both searchable and editable.

How to Convert PDF to Image without PHP

Step 1. Open PDF

First, Install and run PDFelement to get into the main window. On the bottom left is the "Open File" button. Click on this button and it should lead you to the file explorer window. Navigate to the folder where the target PDF is located. Select the PDF and click "Open" to import it to the program.

how to convert pdf to image in php

Step 2. Click "To Image"

Now the target file should be successfully uploaded. On the toolbar, choose the "Convert" tab to access several output formats. Ignore other options and select the "To Image" option.

pdf to image php script

Step 3. Save the Image

Upon choosing the "To Image" option, the program will display the output "Save As" window. Select a suitable output folder and provide a file name of your choice or just leave it with the default name. Click the "Save as type" arrow then select the target image format from the subsequent list. Now click the "Save" button to convert your PDF to the selected image format.

php pdf to image

This is how you can seamlessly convert PDF to image without PHP.

Free Download or Buy PDFelement right now!

Free Download or Buy PDFelement right now!

Buy PDFelement right now!

Buy PDFelement right now!


Elise Williams

chief Editor

Home > Knowledge of PDF > How to Convert PDF to Image using PHP

Other Popular Articles From Wondershare