dlin/snappy-bundle 问题修复 & 功能扩展

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

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

dlin/snappy-bundle

Composer 安装命令:

composer require dlin/snappy-bundle

包简介

Symfony Bundle for Snappy ( wkhtmltopdf )

README 文档

README

Dlin Symfony Snappy Bundle is wrapper bundle for Snapy :

Snappy is a PHP5 library allowing thumbnail, snapshot or PDF generation from a url >or a html page. It uses the excellent webkit-based wkhtmltopdf and wkhtmltoimage >available on OSX, linux, windows.

Dlin Symfony Snappy Bundle provides a configurable service to work with PDF files

Installation

Installation using Composer

NOTE: Unfortunately, Composer does not support repositories in nested dependencies, we have to include dependencies and repositories in the root composer.json.

Add to your composer.json:

json
{
    "require" :  {
        ....
        "dlin/snappy-bundle": "dev-master",
        "google/wkhtmltopdf-amd64": "0.11.0-RC1",
        "google/wkhtmltopdf-i386": "0.11.0-RC1",
    },

    ....

    "repositories": [
        {
            "type": "package",
            "package": {
                "name": "google/wkhtmltopdf-amd64",
                "version": "0.11.0-RC1",
                "dist": {
                    "url": "http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.11.0_rc1-static-amd64.tar.bz2",
                    "type": "tar"
                }
            }
        },
        {
            "type": "package",
            "package": {
                "name": "google/wkhtmltopdf-i386",
                "version": "0.11.0-RC1",
                "dist": {
                    "url": "http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.11.0_rc1-static-i386.tar.bz2",
                    "type": "tar"
                }
            }
        }
    ]
}

Enable the bundle in you AppKernel.php

public function registerBundles()
{
    $bundles = array(
    ...
    new Dlin\Bundle\SnappyBundle\DlinSnappyBundle(),
    ...
}

Configuration

You can specify the installation location of wkhtmltopdf

#app/config/config.yml

dlin_snappy:
    pdf_service:
        wkhtmltopdf: /Applications/wkhtmltopdf.app/Contents/MacOS/wkhtmltopdf

For most OS, this bundle will try to download and install the wkhtmltopdf binary itself. No configuration is required unless you want to use a different wkhtmltopdf binary. For Mac servers, one will have to download the DMG file and install it. The above configuration is required.

Usage

Geting the service in a controller

$pdf =  $this->get('dlin.pdf_service');

Getting the service in a ContainerAwareService

$pdf = $this->container->get('dlin.pdf_service');

Using the method "createPdfFromHtml"

#Pdf will be created (replace if already exist) as file '/tmp/test.pdf'
$pdf->createPdfFromHtml('<html><body><h1>hello</h1></body>', '/tmp/test.pdf');

Using the method "createPdfFromUrl"

#Pdf will be created (replace if already exist) as file '/tmp/test.pdf'
$pdf->createPdfFromUrl('google.com', '/tmp/test.pdf');

Download to browser (HTTP headers will be set and script terminates)

$pdf->sendHtmlAsPdf('<html><body><h1>hello</h1></body>', 'downloadFileName.pdf');
#or
$pdf->sendUrlAsPdf('google.com', 'downloadFileName.pdf');

Show PDF inline in browser (HTTP headers will be set and script terminates)

$pdf->sendHtmlAsPdf('<html><body><h1>hello</h1></body>', 'downloadFileName.pdf', true);
#or
$pdf->sendUrlAsPdf('google.com', 'downloadFileName.pdf', true);

Notes

  • MAMP user couldl have problem using wkhtmltopdf. Please solve the problem here
  • Mac OSX requires its own wkhtmltopdf binnary. You can download it here.
  • On your *nix server, you might need to install a library (sudo apt-get install libxrender1)

License

MIT

Free Software, Yeah!

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2013-06-27

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固