PHPackages                             spacecatninja/imager-x-pdf-adapter - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PDF &amp; Document Generation](/categories/documents)
4. /
5. spacecatninja/imager-x-pdf-adapter

ActiveCraft-plugin[PDF &amp; Document Generation](/categories/documents)

spacecatninja/imager-x-pdf-adapter
==================================

File adapter for transforming PDFs in Imager X

1.1.1(1mo ago)12.5k↓57.6%[1 issues](https://github.com/spacecatninja/craft-imager-x-pdf-adapter/issues)MITPHPPHP ^8.0.2

Since Jun 16Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/spacecatninja/craft-imager-x-pdf-adapter)[ Packagist](https://packagist.org/packages/spacecatninja/imager-x-pdf-adapter)[ RSS](/packages/spacecatninja-imager-x-pdf-adapter/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (4)Versions (4)Used By (0)

Imager X PDF Adapter plugin for Craft CMS
=========================================

[](#imager-x-pdf-adapter-plugin-for-craft-cms)

A plugin for transforming PDFs using Imager X.
Also, an example of [how to make a custom file adapter for Imager X](https://imager-x.spacecat.ninja/extending.html#file-adapters).

Requirements
------------

[](#requirements)

This plugin requires Imager X 4.1+/5.0+, Craft CMS 4.0+/5.0+, PHP 8.0+ and Imagick *with support for opening PDFs*.

### Support for opening PDFs, what does it mean?

[](#support-for-opening-pdfs-what-does-it-mean)

As a start, it means that ghostscript needs to be installed on the server, and available to ImageMagick as a delegate format. It usually is.

Where you're more likely to encounter issues is that in some environments access to open PDFs may be restricted by your [ImageMagick policy file](https://twitter.com/nystudio107/status/1363124167764238337). This is an XML file that sets the resource and security policy for ImageMagick, and in turn Imagick. On Ubuntu, it's located in /etc/ImageMagick-6/policy.xml (if you have ImageMagick 6, replace the 6 with 7 if that's what's installed), a google search will probably help you figure out where it is on your distro.

If you get an error (on your log or debug bar) saying something about PDFs and policy, you probably have this in that file:

```

```

Changing the rights to `read|write`:

```

```

Make sure to restart your webserver/php-fpm after making changes, or the old settings will be cached. If that didn't work there're more tips [in this StackOverflow-thread](https://stackoverflow.com/questions/52998331/imagemagick-security-policy-pdf-blocking-conversion)that you can try.

Installation
------------

[](#installation)

To install the plugin, follow these instructions:

1. Install with composer via `composer require spacecatninja/imager-x-pdf-adapter` from your project directory.
2. Install the plugin in the Craft Control Panel under Settings → Plugins, or from the command line via `./craft install/plugin imager-x-pdf-adapter`.

---

Usage
-----

[](#usage)

Install and configure the adapter as described below.

You can now transform PDF files simply by adding a PDF file to Imager's `transformImage` method:

```
{% set transforms = craft.imagerx.transformImage(myPdfAsset, { width: 200 }) %}

```

You can pass configuration parameters to the adapter, using the `adapterParams` transform parameter:

```
{% set transforms = craft.imagerx.transformImage(myPdfAsset, { width: 200, adapterParams: { density: 72, page: 5 } }) %}

```

You can also create the adapter as a separate step, with the advantage of being able to better control settings, and inspecting the PDF.

```
{% set pdf = craft.pdfadapter.load(asset, { density: 300 }) %}

# pages: {{ pdf.getNumPages() }}

{% do pdf.setPage(5) %}
{% set transformPage5 = craft.imagerx.transformImage(pdf, { width: 600 }) %}

{% do pdf.setPage(pdf.getNumPages()) %}
{% set transformLastPage = craft.imagerx.transformImage(pdf, { width: 600 }) %}

```

### Auto generation

[](#auto-generation)

The PDF adapter works perfectly with the [auto generation functionality](https://imager-x.spacecat.ninja/usage/generate.html)in Imager. The only thing you need to do, is add `pdf` to the list of safe file formats to transform, using the config setting ['safeFileFormats'](https://imager-x.spacecat.ninja/configuration.html#safefileformats-array).

```
'safeFileFormats' => ['jpg', 'jpeg', 'gif', 'png', 'pdf']

```

Configuring
-----------

[](#configuring)

You can configure the adapter by creating a file in your config folder called `imager-x-pdf-adapter.php`, and override settings as needed.

### defaultDensity \[int\]

[](#defaultdensity-int)

Default: `144`
Sets the default density/dpi to use when converting from pdf to bitmap image.

The higher the number, the larger the resulting file will be, and the better the quality. But it'll also require more resources, and opening PDFs is a resource intensive endeavour, so be careful.

### defaultFormat \[string\]

[](#defaultformat-string)

Default: `'png'`
Sets the default format of the temporary bitmap image that the adapter generates. You can of course transform this to whatever format you'd like later, using Imager.

### cacheEnabled \[bool\]

[](#cacheenabled-bool)

Default: `true`
Enables/disables caching of generated images. Only disable this if testing, as it will seriously impact performance.

### cacheDuration \[bool|int\]

[](#cacheduration-boolint)

Default: `false`
Sets the cacheDuration that's used if `cacheEnabled` is `true`. By default, forever. Clearing the Imager runtime cache will also clear this cache.

---

Price, license and support
--------------------------

[](#price-license-and-support)

The plugin is released under the MIT license. It requires Imager X, which is a commercial plugin [available in the Craft plugin store](https://plugins.craftcms.com/imager-x).

###  Health Score

42

—

FairBetter than 89% of packages

Maintenance73

Regular maintenance activity

Popularity22

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~718 days

Total

3

Last Release

34d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/806fbb515be53ddbca1d658f1abe7f8ddd41d77b72eec8aa85800db3a03e7e35?d=identicon)[spacecatninja](/maintainers/spacecatninja)

---

Top Contributors

[![aelvan](https://avatars.githubusercontent.com/u/2675644?v=4)](https://github.com/aelvan "aelvan (6 commits)")

---

Tags

pdfcmsCraftcraftcmscraft-pluginimager

### Embed Badge

![Health badge](/badges/spacecatninja-imager-x-pdf-adapter/health.svg)

```
[![Health](https://phpackages.com/badges/spacecatninja-imager-x-pdf-adapter/health.svg)](https://phpackages.com/packages/spacecatninja-imager-x-pdf-adapter)
```

###  Alternatives

[verbb/formie

The most user-friendly forms plugin for Craft.

100387.6k57](/packages/verbb-formie)[enupal/snapshot

PDF or Image generation from a Url or HTML page

1138.0k](/packages/enupal-snapshot)[verbb/vizy

A flexible visual editor field for Craft.

4249.7k](/packages/verbb-vizy)[verbb/hyper

A user-friendly links field for Craft.

24142.6k12](/packages/verbb-hyper)[verbb/social-poster

Automatically post entries to social media.

918.5k](/packages/verbb-social-poster)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
