vivutio/pdf-scribe-bundle
最新稳定版本:v0.1.0-alpha
Composer 安装命令:
composer require vivutio/pdf-scribe-bundle
包简介
Symfony 7/8 bundle for PDF generation using Chrome Headless
README 文档
README
A Symfony 7/8 bundle for generating PDFs using Chrome Headless. Provides excellent CSS support with the modern Chrome rendering engine.
Installation
composer require vivutio/pdf-scribe-bundle
Configuration
Create config/packages/pdf_scribe.yaml:
pdf_scribe: binary_path: '%env(PDF_SCRIBE_BINARY)%' timeout: 120 options: print-background: true no-pdf-header-footer: true
Add to .env:
# macOS PDF_SCRIBE_BINARY="/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" # Linux PDF_SCRIBE_BINARY=/usr/bin/chromium-browser
Usage
use Vivutio\PdfScribeBundle\Contract\PdfGeneratorInterface; class InvoiceController extends AbstractController { public function download(Invoice $invoice, PdfGeneratorInterface $pdf): Response { $html = $this->renderView('invoice/pdf.html.twig', [ 'invoice' => $invoice, ]); $content = $pdf->fromHtml($html); return new Response($content, 200, [ 'Content-Type' => 'application/pdf', 'Content-Disposition' => 'attachment; filename="invoice.pdf"', ]); } }
API
PdfGeneratorInterface
fromHtml(string $html, array $options = []): string- Generate PDF from HTML stringfromUrl(string $url, array $options = []): string- Generate PDF from URLsaveFromHtml(string $html, string $outputPath, array $options = []): void- Save PDF from HTML to filesaveFromUrl(string $url, string $outputPath, array $options = []): void- Save PDF from URL to file
Options
| Option | Type | Description |
|---|---|---|
print-background |
bool | Print background graphics |
no-pdf-header-footer |
bool | Remove default header/footer |
landscape |
bool | Landscape orientation |
scale |
float | Scale factor (0.1 to 2.0) |
CSS @page Rules
Control page size and margins via CSS in your HTML template:
@page { size: A4; margin: 15mm; } @media print { body { -webkit-print-color-adjust: exact; print-color-adjust: exact; } }
License
MIT
统计信息
- 总下载量: 27
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-28