subtlephp/phpwkhtmltox

This package is not installable via Composer 1.x, please make sure you upgrade to Composer 2+. Read more about our Composer 1.x deprecation policy.

PHP wrapper for wkhtmltox

dev-master 2017-12-29 16:33 UTC

This package is not auto-updated.

Last update: 2021-07-17 23:26:36 UTC


README

为了用 PHP 解决 HTML 转 PDF 的麻烦, 简单的封装了一个库, 它的主要作用有两个:

  1. 解析数组形式的配置
  2. 调用 wkthmltopdf 二进制文件生成 PDF

解析数组形式的配置

更有三种形式的选项

  1. 类似--header-line, 是单独的选项, 不带值, 在配置里面写作:
[
    'header-line' => '',
]
  1. 类似toc这种大类选项, 作为二级数组
[
    'toc' => [
        'toc-header-text' => 'kkkk',
    ],
]
  1. 类似--page-size A4 这种有选项又有值的
[
    'page-size' => 'A4'
]

例子

use SubtlePHP\WkHtmlTo\PDF\Factory;

require __DIR__ . '/../../vendor/autoload.php';

$pdf = (new Factory())->setPdfPath(__DIR__ . '/tmp/pdf')
    ->setTemporaryHtmlPath(__DIR__ . '/tmp/html')
    ->setBinary('/usr/local/bin/wkhtmltopdf');

$html = [
    '<p>kdfjsdl</p>',
    '<h1>ksdjflsadj</h1>',
];

$pdf->generateFromHtml($html, 'test', [
    'print-media-type' => '',
]);