PDF Transform is a Craft CMS plugin that transforms a PDF stored in Assets, to an image. This can then be output via Twig in to a template.
A use case for this is to show the preview of a PDF before a user downloads that particular file.
Features
- Transform PDF's to images via Twig (The file needs to be an existing Asset element)
- PDF's are transformed to an image when PDF's are uploaded via Assets or Asset fields.
- Transformed PDF images are indexed and available in Assets like all other asset elements.
- Works with local asset volumes, Amazon S3 and Servd.
Configuration
Setting | Default | Description |
Page Number | 1 | Set with page should in the PDF should be converted to an image. |
Image Volume | null | Choose where converted images should be stored. |
Image Resolution | 72 | Set the resolution of the converted image. |
Image Format | jpg | Set the file format of the converted image. |
Image Quality | 100 | Set the image quality of the converted image. |
Templating
To transform a PDF to an image use the following Twig tag:
{% set pdfToTransform = entry.pdfAsset.one() %}
{% set transformedPdf = craft.pdfTransform.render(pdfToTransform) %}
{{ transformedPdf.one().url }}
The transformed PDF (Now an image stored in Assets) can then be output using {{ transformedPdf.one().url }}
. Or get any Asset property e.g. title
, id
, filename
etc.
If the transformed image doesn't exist then the PDF will be transformed via the template. This may cause the template/page to become slow whilst the PDF is transformed.
Be aware that this also may output a large image, so we'd recommend running this through an image transform.
To install this plugin, copy the command above to your terminal.
This plugin doesn't have any reviews.