定制 kriansa/h2p 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

kriansa/h2p

最新稳定版本:v2.0.0

Composer 安装命令:

composer require kriansa/h2p

包简介

A simple library to convert HTML files to PDF using PhantomJS

README 文档

README

Convert your HTML files to PDF with ease. Thanks to PhantomJS, you can write CSS3, HTML5 and Javascript and it will convert and print your files just like you see them in your browser.

How to use

It's very simple, but first you must download the PhantomJS binary file according to your system (Windows, Mac, Linux-X86 or Linux-X86_64) and put it in the right bin folder.

You can download it here: http://phantomjs.org/download.html

Getting started

use H2P\Converter\PhantomJS;

$converter = new PhantomJS();

// Convert destination accepts H2P\TempFile or string with the path to save the file
$converter->convert('http://www.google.com/', '/home/user/Documents/page.pdf');

If you want to convert a HTML string, do it like so:

use H2P\Converter\PhantomJS;
use H2P\TempFile;

$converter = new PhantomJS();
$input = new TempFile('<b>test string to pdf</b>', 'html'); // Make sure the 2nd parameter is 'html'

// Convert destination accepts H2P\TempFile or string with the path to save the file
$converter->convert($input, '/home/user/Documents/page.pdf');

Advanced usage

use H2P\Converter\PhantomJS;
use H2P\TempFile;
use H2P\Request;
use H2P\Request\Cookie;

$converter = new PhantomJS(array(
    // You should use 'search_paths' when you want to point the phantomjs binary to somewhere else
    // 'search_paths' => shell_exec('which phantomjs'),
    'orientation' => PhantomJS::ORIENTATION_LANDSCAPE,
    'format' => PhantomJS::FORMAT_A4,
    'zoomFactor' => 2,
    'border' => '1cm',
    'header' => array(
        'height' => '1cm',
        'content' => "<h1>{{pageNum}} / {{totalPages}}</h1>",
    ),
    'footer' => array(
        'height' => '1cm',
        'content' => "<h1>{{pageNum}} / {{totalPages}}</h1>",
    ),
));

// Create a full custom request
$request = new Request(
    'http://www.google.com/',
    Request::METHOD_POST,
    array('param' => 'value'), // POST params
    array('X-Header' => 'value'), // Custom headers
    array(
        new Cookie('Cookie', 'value', 'domain'), // Create a basic cookie
    )
);

$destination = new TempFile();
$converter->convert($request, $destination);

You can find more examples in the samples folder.

Composer

Just put { "kriansa/h2p": "dev-master" } into your require property.

License

  • MIT License

统计信息

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

GitHub 信息

  • Stars: 74
  • Watchers: 10
  • Forks: 37
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2013-03-24