Fieldtype/Inputfield module for ProcessWire allowing easy generation of thumbnails of the PDF files
Module for ProcessWire CMS allowing you to easily generate images from the PDF files embedded to the site.
- How to use
- API documentation
- Upgrading from 1.0.1 and lower
- Processwire 2.5+
- ImageMagick PHP extension
In your ProcessWire installation root run:
composer require uiii/processwire-fieldtypepdf
Login to your ProcessWire admin and go to Modules > Refresh and install the module.
If you want to read more about ProcessWire and Composer visit https://processwire.com/blog/posts/composer-google-calendars-and-processwire/
Add a field and set its type to
Image generation is highly configurable (image format, extension, background, ...). See the PDF to image converter section on field's Details tab.
There are some backward-compatible API changes against the version 1.0.1 and lower, see Upgrading from 1.0.1 and lower.
The PDF field extends file field and adds new hookable
___toImage($page = 0, $options = array()) method to generate the image from PDF.
$image = $page->pdfFile->toImage(); $image->size(100, 100);
Method accepts two optional parameters. First is the
$page, which specifies the PDF's page number the image is generated from, default is 0. The exception is thrown if the page is out of range.
The second is
$options parameter, which is an array of options to override the options set in administration.
$options = array( 'suffix' => array('suffix1', 'suffix2'), // suffixes used in filename 'forceNew' => false, // if TRUE the image is regenerated if already exists 'format' => 'JPEG', // image format 'extension' => 'jpg', // image file extension 'background' => '#FFFFFF', // background color used when the PDF has transparent background 'resolution' => '300x300', // resolution used when reading the PDF 'colorspace' => Imagick::COLORSPACE_RGB, // colorspace used when reading the PDF 'imagickOptions' => array( // ImageMagick options 'pdf:use-cropbox=true' ) )
For each combinations of page and suffixes there will be one image. The generated images are saved in page's assets and will be created only once until forceNew options is TRUE. The image is the instance of
Pageimage, so you can do with it whatever you can do with the image field. When you delete the PDF file the generated images are deleted too.
Generate into doc directory:
apigen generate -d doc
DO NOT run the tests against the production site. They modify the fields, templates and pages as they need, so can potentially damage your site!
Prepare the PW testing installation and export the
PW_PATH environment variable containing the path to the root of that installation. Copy the module sources in the
Install required packages:
Run the tests
You can also automatically test against multiple ProcessWire versions. It uses Tense tool for it.
Install reuquired packages:
Run the tests:
WARNING: The tool will ask you for database connection parameters. Configure the
dbconnection parameters carefully because it creates and drops a database for each ProcessWire installation.
In 1.1.0 some methods of class PagePDF are deprecated. See the list here. You doesn't have to make any changes but it is recommended to use the new API, for compatibility with later versions.
Instructions for replacing the deprecated methods:
$page->pdf->thumbnail($width, $height)replace with the code
$image = $page->pdf->toImage(); $image->size($width, $height);
NOTE: There is certain incompatibility between these two methods. While
isThumbnailreturns TRUE for all the images generated from the PDF and also theirs derivatives (e.g. pdf.jpg, pdf.100x100.jpg), the
isImageOfThisreturn TRUE only for the images generated directly from PDF (e.g. pdf.jpg). That doesn't change much, because you can use it in combination with
To fix that, you need to made some changes in ImageMagick delegate files. Detailed instructions can be found here: http://www.lassosoft.com/CMYK-Colour-Matching-with-ImageMagick
If you got some GhostScript exceptions when generating image, update GhostScript and ImageMagick to the latest versions.
If you can't, you can use the fallback mode. Turn it on in the module's settings.
Be aware of that this will produce low quality images and most of the field type options won't be abvailable.