dmitrivereshchagin/yii-snappy 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

dmitrivereshchagin/yii-snappy

最新稳定版本:v1.0.0

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.

统计信息

  • 总下载量: 7.51k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-10-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固