dmitrivereshchagin/yii-snappy
Composer 安装命令:
composer require dmitrivereshchagin/yii-snappy
包简介
Basic wrapper around Snappy implemented as Yii component
README 文档
README
This is a basic wrapper around Snappy implemented as Yii application component. Snappy is a PHP library that uses wkhtmltopdf and wkhtmltoimage to render HTML into PDF and various image formats.
Installation
Installation using Composer should be straightforward
% composer require dmitrivereshchagin/yii-snappy
To register components in your application add something like the
following in configuration components section:
'pdf' => array( 'class' => 'dmitrivereshchagin\\yii\\snappy\\PdfComponent', 'binary' => '/usr/local/bin/wkhtmltopdf', 'options' => array('orientation' => 'landscape'), 'tempdir' => basename(__DIR__).'/runtime/pdf', ), 'image' => array( 'class' => 'dmitrivereshchagin\\yii\\snappy\\ImageComponent', 'binary' => '/usr/local/bin/wkhtmltoimage', 'tempdir' => basename(__DIR__).'/runtime/image', ),
Specifying paths to binaries is mandatory. Optionally you can configure
default command line arguments that can be overridden or adjusted later.
It is also possible to set temporary directory for both components using
snappyTempdir application parameter.
Usage
Use Yii::app()->pdf and Yii::app()->image to generate PDF documents
and images respectively. These components provide access to methods
declared by \Knp\Snappy\GeneratorInterface.
Here are some examples.
Generate image from an URL
Yii::app()->image->generate('http://example.com', '/path/to/image.jpg');
Generate PDF document from an URL
Yii::app()->pdf->generate('http://example.com', '/path/to/document.pdf');
Generate PDF document from multiple URLs
Yii::app()->pdf->generate( array('http://example.com', 'http://example.org'), '/path/to/document.pdf' );
Generate PDF document from a view
Yii::app()->pdf->generateFromHtml( $this->render('view', array('name' => $value), $return = true), '/path/to/document.pdf' );
Generate PDF document as response from controller
$html = $this->render('view', array('name' => $value), $return = true); Yii::app()->request->sendFile( 'document.pdf', Yii::app()->pdf->getOutputFromHtml($html) );
Generate PDF document with relative URLs inside
$url = Yii::app()->createAbsoluteUrl('controller/action'); Yii::app()->request->sendFile( 'document.pdf', Yii::app()->pdf->getOutput($url) );
Credits
This code uses Snappy library. Snappy has been originally developed by KnpLabs team.
dmitrivereshchagin/yii-snappy 适用场景与选型建议
dmitrivereshchagin/yii-snappy 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7.52k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2015 年 10 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「snappy」 「pdf」 「yii」 「wkhtmltopdf」 「wkhtmltoimage」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 dmitrivereshchagin/yii-snappy 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 dmitrivereshchagin/yii-snappy 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 dmitrivereshchagin/yii-snappy 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
MvlabsSnappy is a Zend Framework and Laminas module that allow easy to thumbnail, snapshot or PDF generation from a url or a html page using Snappy PHP wrapper for the wkhtmltopdf/wkhtmltoimage conversion utility.
Yii2 LightBox image galary widget uses Lightbox v2.10.0 by Lokesh Dhakar
Priveate for SkeekS CMS
Snappy Service Provider for Silex
Snappy PDF/Image for Laravel
C3JS Chart for Yii Framework 2.0
统计信息
- 总下载量: 7.52k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 28
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-10-18