logo.png

The PDF To ImageField module provides automatic conversion of uploaded PDF files to images.
It can be used either to create a snapshot of the front page to use as a preview thumbnail, or to generate a gallery of images from each page in the document.

The module is implemented as an additional widget for File Field where PDFs are uploaded to. It places generated images into a Image Field on the same content type.

Requirements:

D9/D10 1.0.x

  • PHP version >= 7.4
  • Recommended Drupal version >= 9.5

D7 7.x-3.x

  • Core only. imagemagick.module is now optional.
  • Imagemagick commandline utility is still required on the server however.

Installation (1.0.x)

Just composer install and configure the file widget.

Installation (7.x-3.x)

You must have the imagemagick tools available on your server, and able to be called from the commandline.
Running
which convert
on your server should tell you if and where the binary exists.

Once the module is enabled, check your site status at /admin/reports/status
You should see a message that will tell you if your system is ready to run.
"Imagemagick support for PDF to Image"
If not, you need to check the requirements, and the ImageMagick settings at admin/config/media/image-toolkit.
See the ImageMagick project docs for troubleshooting that.

If ImageMagick appears to be available but still does not convert PDFs, it could be it wasn't installed with 'Ghostscript' libraries or other required dependencies. You'l have to go to the ImageMagick forums for help with that.

There is a drush make file and a 'Features' demo example you can use to help set
up and try this functionality immediately.

Use drush make to fetch all required modules

  • If you have "drush" and "drush make" :
  • Change to a working directory you want to install a new site into.
  • Run
        drush make http://drupalcode.org/project/pdf_to_imagefield.git/blob_plain/refs/heads/7.x-3.x:/pdf_to_image_demo.make.stub
    

    This will download all the dependencies required to run pdf_to_imagefield and the demo feature pdf_document.

  • Install the Drupal site and configure the database as usual.

Configuration

  • First, add an imagefield on your chosen content type. This is where the generated images wil be stored.
  • Set the allowed fields to 1 if you just want a cover page, or 'unlimited' if you want all pages to be generated.
  • Next add a filefield to your chosen content type and choose 'PDF to Image' as the widget.
    • D7 - This filefield should be configured to only accept PDF file types.
    • D9/D10 - This filefield should be configured to accept PDF file types (required) + you can add the same extensions as for the target field.
  • When configuring this field, you will be required to link the uploaded file field with the target image field.
  • You can add image style handling to the imagefield rendering as normal to adjust the size of the results and how they display on the page.

Processing

Processing of PDF may take some time.
Larger documents use the 'batch' process to generate each page.

Comparison:

  • PDF Preview now offers similar functionality. It only does the first page, and operates as a 'formatter' for the uploaded file rather than treating the generated image as an attached file.
  • See also PDF Preview Image to prepare a preview image from PDF
Supporting organizations: 

Project information

Releases