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
kriansa/h2p 适用场景与选型建议
kriansa/h2p 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 104.3k 次下载、GitHub Stars 达 74, 最近一次更新时间为 2026 年 01 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「pdf」 「html」 「phantomjs」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 kriansa/h2p 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 kriansa/h2p 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 kriansa/h2p 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Texy converts plain text in easy to read Texy syntax into structurally valid (X)HTML. It supports adding of images, links, nested lists, tables and has full support for CSS. Texy supports hyphenation of long words (which reflects language rules), clickable emails and URL (emails are obfuscated again
HTML to PDF Symfony bundle. Works with Puppeteer, PhantomJS, and more.
PhantomJS client for SERPS
PHP Automation Tools
HTML and form generation
A modern HTML DOM parser for PHP using DOMDocument and Symfony CssSelector.
统计信息
- 总下载量: 104.3k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 74
- 点击次数: 21
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-04