定制 asyncphp/paper 二次开发

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

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

asyncphp/paper

Composer 安装命令:

composer require asyncphp/paper

包简介

Hassle-free HTML to PDF conversion abstraction library

README 文档

README

Hassle-free HTML to PDF conversion abstraction library.

Installation

composer require asyncphp/paper

For best results, you should also install Prince and WKHTMLtoDPF. To run the tests, you'll also need to install diff-pdf. If you don't have the latter installed, you'll not be able to run the tests. If you don't have the former installed, the relevant tests will be skipped, and drivers unusable.

Usage

You can use any of the drivers directly:

use AsyncInterop\Loop;
use AsyncPHP\Paper\Driver\DomDriver;
use AsyncPHP\Paper\Runner\AmpRunner;

Loop::execute(Amp\wrap(function() use ($sample) {
    $driver = new DomDriver();
    $runner = new AmpRunner();

    $promise = $driver
        ->html($sample)
        ->size("A4")
        ->orientation("portrait")
        ->dpi(300)
        ->render($runner);

    $results = yield $promise;
}));

However, it's must easier to use the factory, to create pre-configured drivers:

use AsyncPHP\Paper\Factory;

$config = [
    "driver" => "dom",

    "dom" => [
        "options" => [
            "fontDir" => __DIR__ . "/fonts",
            // https://github.com/dompdf/dompdf/blob/master/src/Options.php
        ],
    ],

    "prince" => [
        "binary" => "/opt/prince/bin/prince",
        "tempPath" => __DIR__,
        "options" => [
            "--no-compress",
            "--http-timeout" => 10,
            // https://www.princexml.com/doc/command-line/#command-line
        ],
    ],

    "webkit" => [
        "binary" => "/usr/local/bin/wkhtmltopdf",
        "tempPath" => __DIR__,
        "options" => [
            "--grayscale",
            "--javascript-delay" => 500,
            // http://wkhtmltopdf.org/usage/wkhtmltopdf.txt
        ],
    ],

    "runner" => "amp",
];

$factory = new Factory();
$driver = $factory->createDriver($config);
$runner = $factory->createRunner($config);

yield $driver->html($sample)->render($runner);

Paper takes an async-first approach. Operations, like rendering PDF files, are particularly suited to parallel processing architecture. You may be stuck rending PDF files in a synchronous architecture, in which case you can use the SyncDriver decorator:

$driver = new SyncDriver(new DomDriver());

// ...or with the factory

$driver = $factory->createDriver([
    "driver" => "dom",
    "sync" => true,
]);

Drivers

Here's a list of the drivers to currently support:

DOMPDF

  • Requires command-line utilities: no
  • Supports modern CSS: no
  • Supports modern JS: no
  • Produces vector files: yes
  • Open + free: yes

WKHTMLtoDPF

  • Requires command-line utilities: yes
  • Supports modern CSS: yes
  • Supports modern JS: yes
  • Produces vector files: yes
  • Open + free: yes

Prince

  • Requires command-line utilities: yes
  • Supports modern CSS: yes
  • Supports modern JS: yes
  • Produces vector files: yes
  • Open + free: no

Runners

Paper supports Amp and React, to package and run the async code. You have to install one of the following library groups:

Amp

composer require amphp/loop
composer require amphp/parallel
composer require async-interop/event-loop

React

composer require react/event-loop
composer require react/child-process
composer require jeremeamia/superclosure

Take a look at the examples folder to find out more about using the async drivers.

Roadmap

  • Setters for default margin
  • Setters for header HTML
  • Setters for footer HTML
  • More drivers (especially DocRaptor – a SaaS version of Prince)

Versioning

This library follows Semver. According to Semver, you will be able to upgrade to any minor or patch version of this library without any breaking changes to the public API. Semver also requires that we clearly define the public API for this library.

All methods, with public visibility, are part of the public API. All other methods are not part of the public API. Where possible, we'll try to keep protected methods backwards-compatible in minor/patch versions, but if you're overriding methods then please test your work before upgrading.

统计信息

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

GitHub 信息

  • Stars: 196
  • Watchers: 8
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-01-15

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固