alifahmmed/pdfbuilder
Composer 安装命令:
composer require alifahmmed/pdfbuilder
包简介
Laravel 12 package: generate PDF via headless chromium or wkhtmltopdf without Node.js
关键字:
README 文档
README
PdfBuilder is a Laravel package for generating high-quality PDFs from HTML using wkhtmltopdf or headless Chromium — without requiring Node.js.
It supports Bootstrap, Tailwind CSS, and any modern HTML/CSS styling.
✨ Features
- Convert HTML to PDF directly in Laravel
- No Node.js required
- Supports Bootstrap and TailwindCSS
- Works with
wkhtmltopdfbinary (bundled or system-installed) - Simple Facade API (
PdfBuilder::htmlToPdf()) - Configurable binary path, temp storage, and extra arguments
- Publish binary to your Laravel project for easy server deployment
- Works on Laravel 9, 10, 11, and 12
📦 Installation
Require the package via Composer:
composer require alifahmmed/pdfbuilder
⚙️ Configuration
- Publish the config file and binary:
php artisan vendor:publish --provider="AlifAhmmed\PdfBuilder\PdfBuilderServiceProvider" --tag=config php artisan vendor:publish --provider="AlifAhmmed\PdfBuilder\PdfBuilderServiceProvider" --tag=bin
- Set up your .env variables:
PDFBUILDER_BINARY_PATH=/full/absolute/path/to/your/project/pdf-builder-bin/wkhtmltopdf PDFBUILDER_RENDERER=wkhtmltopdf
- Configuration file (config/pdfbuilder.php):
return [ 'default_renderer' => 'wkhtmltopdf', 'binary_path' => env('PDFBUILDER_BINARY_PATH', 'wkhtmltopdf'), 'temp_path' => env('PDFBUILDER_TEMP_PATH', storage_path('app/pdfbuilder')), 'extra_args' => [ '--enable-local-file-access', '--no-outline', '--quiet', ], ];
🚀 Basic Usage
Generate a PDF from HTML and return it as a download in a Laravel controller:
use PdfBuilder; class PdfController extends Controller { public function download() { $html = view('pdf.invoice', ['data' => $invoiceData])->render(); $pdfContent = PdfBuilder::htmlToPdf($html); return response($pdfContent) ->header('Content-Type', 'application/pdf') ->header('Content-Disposition', 'attachment; filename="invoice.pdf"'); } }
🎯 Advanced Usage
- Set Custom Page Options
$pdfContent = PdfBuilder::htmlToPdf($html, [ 'orientation' => 'landscape', // 'portrait' or 'landscape' 'margin' => '10mm', ]);
- Inline Local Images Automatically
use AlifAhmmed\PdfBuilder\Helpers; $html = file_get_contents(resource_path('views/pdf/report.html')); $htmlWithImages = Helpers::inlineImages($html, public_path('images')); $pdfContent = PdfBuilder::htmlToPdf($htmlWithImages);
- Store PDF to Disk
Storage::put('reports/monthly.pdf', PdfBuilder::htmlToPdf($html));
🛠 Requirements
- PHP >= 8.1
- Laravel 9.x | 10.x | 11.x | 12.x
- wkhtmltopdf binary (system-installed or bundled via resources/bin)
🐛 Troubleshooting
-
Binary not found Ensure wkhtmltopdf is installed or the .env path is correct.
-
Permission denied Make sure the binary is executable:
chmod +x pdf-builder-bin/wkhtmltopdf
- Fonts/CSS not applied Use absolute paths or the Helpers::inlineImages() method to embed assets.
📜 License
This package is open-sourced under the MIT license.
alifahmmed/pdfbuilder 适用场景与选型建议
alifahmmed/pdfbuilder 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 08 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「javascript」 「css」 「bootstrap」 「pdf」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 alifahmmed/pdfbuilder 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 alifahmmed/pdfbuilder 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 alifahmmed/pdfbuilder 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Generates a Blade directive exporting all of your named Laravel routes. Also provides a nice route() helper function in JavaScript.
A Twig extension to insert css as inline styles with a tag
Caching and compression for Twig assets (JavaScript and CSS).
A pretty nice way to expose your translation messages to your JavaScript.
PHP client for the Google Closure Compiler API in one file.
Yii2 integration for AirBnB Polyglot.js
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 31
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-08-14