crawly / html-to-pdf
用于将HTML转换为PDF的库,为爬虫提供安全转换方式。
1.0.0
2020-09-11 22:13 UTC
Requires
- php: >=7.2
- ext-dom: *
- ext-libxml: *
- ext-mbstring: *
- mikehaertl/phpwkhtmltopdf: ^2.4
This package is auto-updated.
Last update: 2024-09-15 05:39:30 UTC
README
用于将HTML转换为PDF的库,为爬虫提供安全转换方式。
安装
composer require crawly/html-to-pdf
使用示例
<?php
use Crawly\HtmlToPdf;
$html = file_get_contents('my.html');
$htp = new HtmlToPdf($html);
$htp->setBaseUrl('http://www.detran.mg.gov.br')
->safeStripTags()
->sanitizeHtmlHeader()
->sanitizeHtmlText()
->setOptions([
'commandOptions' => [
'useExec' => false,
],
'javascript-delay' => '10000',
'ignoreWarnings' => false
])
->customTransform(function ($html) {
return str_replace('abrir-fechar-table', 'abrir-fechar-table aberto', $html);
});
$pdfBase64 = $htp->convert();