spacecatninja/imager-x-pdf-adapter
Composer 安装命令:
composer require spacecatninja/imager-x-pdf-adapter
包简介
File adapter for transforming PDFs in Imager X
README 文档
README
A plugin for transforming PDFs using Imager X.
Also, an example of how to make a custom file adapter for Imager X.
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?
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. 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:
<policy domain="coder" rights="none" pattern="PDF" />
Changing the rights to read|write:
<policy domain="coder" rights="read|write" pattern="PDF" />
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 that you can try.
Installation
To install the plugin, follow these instructions:
- Install with composer via
composer require spacecatninja/imager-x-pdf-adapterfrom your project directory. - 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
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() }}<br>
{% 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
The PDF adapter works perfectly with the auto generation functionality
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'.
'safeFileFormats' => ['jpg', 'jpeg', 'gif', 'png', 'pdf']
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]
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]
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]
Default: true
Enables/disables caching of generated images. Only disable this if testing, as it
will seriously impact performance.
cacheDuration [bool|int]
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
The plugin is released under the MIT license. It requires Imager X, which is a commercial plugin available in the Craft plugin store.
spacecatninja/imager-x-pdf-adapter 适用场景与选型建议
spacecatninja/imager-x-pdf-adapter 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.66k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2022 年 06 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「cms」 「pdf」 「Craft」 「craftcms」 「imager」 「craft-plugin」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 spacecatninja/imager-x-pdf-adapter 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 spacecatninja/imager-x-pdf-adapter 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 spacecatninja/imager-x-pdf-adapter 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Expand, collapse, change the status of, or delete multiple blocks in a Matrix field simultaneously.
GraphQL authentication for your headless Craft CMS applications.
Set Links with a specific language parameter
Supercharged text field validation.
Integrate with Snipcart.
Restrict user registration by domain in Craft CMS, allows you to limit who can register for your site based on their email address.
统计信息
- 总下载量: 2.66k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-06-16