vortechstudio/html2media
Composer 安装命令:
composer require vortechstudio/html2media
包简介
Html2Media is a versatile Laravel package that allows users to convert HTML content into high-quality PDFs with options for either downloading or triggering a print dialog. Ideal for generating documents, invoices, and reports, this package includes configurable settings for file name, page orientat
README 文档
README
Html2Media is a powerful Laravel Filament package that allows you to generate PDFs, preview documents, and directly print content from your application. 🚀
📌 Overview
The Html2MediaAction provides a set of flexible actions for your Filament resources, enabling:
- 📑 PDF Generation: Convert HTML to a PDF and download it.
- 🖨️ Direct Printing: Print HTML content directly from the application.
- 👀 Document Preview: Preview the content in a modal before printing or exporting.
✨ Features
- 🎨 Customizable File Naming: Define a custom name for the generated PDF.
- 🔍 Preview & Print Options: Preview the content before printing or saving as a PDF.
- 📏 Page Configuration: Adjust page orientation, size, margins, and scaling.
- 🛠️ Advanced PDF Options: Control page breaks, hyperlink inclusion, and more.
🔧 Installation
To install the package, simply run the following command:
composer require torgodly/html2media
Once installed, the Html2MediaAction can be used within your Filament resources or tables.
⚙️ Configuration Methods
Here’s how you can customize your Html2MediaAction!
1. 📂 filename()
Set the name of the generated PDF file. ✍️
Usage:
Html2MediaAction::make('print') ->filename('my-custom-document')
- 🏷️ Default:
'document.pdf' - 🔠 Accepts:
stringorClosure
2. 📄 pagebreak()
Define page break behavior. Customize how and where page breaks occur within the document. 🛑
Usage:
Html2MediaAction::make('print') ->pagebreak('section', ['css', 'legacy'])
-
🔄 Default:
['mode' => ['css', 'legacy'], 'after' => 'section'] -
🛠️ Accepts:
mode: Array of strings (['avoid-all', 'css', 'legacy'])after: Element ID, class, tag, or*for all elements.avoid: (Optional) Element ID, class, or tag to avoid page breaks.
-
📖 More info on page breaks: here.
3. 🔄 orientation()
Set the page orientation for the PDF, either portrait or landscape. 🖼️
Usage:
Html2MediaAction::make('print') ->orientation('landscape')
- 🏷️ Default:
'portrait' - 🔠 Accepts:
string('portrait','landscape') orClosure
4. 📐 format()
Define the format of the PDF, including standard sizes like A4 or custom dimensions. 📏
Usage:
Html2MediaAction::make('print') ->format('letter', 'in')
- 🏷️ Default:
'a4' - 🔠 Accepts:
string,array(e.g.,[width, height]), orClosure
5. 🔗 enableLinks()
Enable or disable automatic hyperlink conversion in the PDF. 🔗
Usage:
Html2MediaAction::make('print') ->enableLinks()
- 🏷️ Default:
false - 🔠 Accepts:
boolorClosure
6. 🔧 scale()
Adjust the scaling factor for HTML to PDF conversion. 🔍
Usage:
Html2MediaAction::make('print') ->scale(2)
- 🏷️ Default:
2 - 🔠 Accepts:
intorClosure
7. 🖨️ print()
Enable or disable the print button in the modal. 🖨️
Usage:
Html2MediaAction::make('print') ->print(true)
- 🏷️ Default:
true - 🔠 Accepts:
boolorClosure
8. 👁️ preview()
Enable a preview option for the document content before printing or saving. 👀
Usage:
Html2MediaAction::make('print') ->preview()
- 🏷️ Default:
false - 🔠 Accepts:
boolorClosure
9. 💾 savePdf()
Enable the option to directly save the content as a PDF. 💾
Usage:
Html2MediaAction::make('print') ->savePdf()
- 🏷️ Default:
false - 🔠 Accepts:
boolorClosure
10. ✅ requiresConfirmation()
Show a confirmation modal before performing the action. 🛑
Usage:
Html2MediaAction::make('print') ->requiresConfirmation()
- 🏷️ Default:
true - 🔠 Accepts:
boolorClosure
11. 💻 content()
Set the content for the document. Typically, you’ll pass a Blade view for the content. 📝
Usage:
Html2MediaAction::make('print') ->content(fn($record) => view('invoice', ['record' => $record]))
- 🔠 Accepts:
View,Htmlable, orClosure
🎨 Example Usage
Here’s a complete example of configuring the Html2MediaAction:
Html2MediaAction::make('print') ->scale(2) ->print() // Enable print option ->preview() // Enable preview option ->filename('invoice') // Custom file name ->savePdf() // Enable save as PDF option ->requiresConfirmation() // Show confirmation modal ->pagebreak('section', ['css', 'legacy']) ->orientation('portrait') // Portrait orientation ->format('a4', 'mm') // A4 format with mm units ->enableLinks() // Enable links in PDF ->margin([0, 50, 0, 50]) // Set custom margins ->content(fn($record) => view('invoice', ['record' => $record])) // Set content
This configuration will:
- 📄 Generate a PDF from the
invoiceBlade view. - 🖨️ Allow users to
previewandprintthe document. - 💾 Enable
saving as PDFand show a confirmation modal before executing. - 📏 Set A4 format with portrait orientation.
- 🔗 Enable links and set custom margins.
📊 Filament Action or Table Action
You can use the Html2MediaAction in the same way, whether it's in a Filament table action or a regular action. Simply import the appropriate class:
use Torgodly\Html2Media\Actions\Html2MediaAction; use Torgodly\Html2Media\Tables\Actions\Html2MediaAction;
This makes the action flexible and usable in various contexts. 🌍
⚡ Quick Example: Direct Print or Save as PDF
- For direct printing:
Html2MediaAction::make('print') ->content(fn($record) => view('invoice', ['record' => $record]))
This will directly open the print dialog for the HTML content. 🖨️
- For saving as PDF:
Html2MediaAction::make('print') ->savePdf() ->content(fn($record) => view('invoice', ['record' => $record]))
This will save the HTML content as a PDF. 💾
🏁 Conclusion
The Html2Media package for Filament makes it easy to generate PDFs, preview documents, and print content directly from your Laravel app. With flexible configuration options, you can tailor it to your specific needs, ensuring smooth document handling. ✨
We hope this documentation helps you get started quickly. 🚀 Happy coding! 🎉
vortechstudio/html2media 适用场景与选型建议
vortechstudio/html2media 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 903 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 07 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「pdf」 「invoice」 「documents」 「laravel」 「reporting」 「printing」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 vortechstudio/html2media 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 vortechstudio/html2media 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 vortechstudio/html2media 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Easy invoice generation using Laravel Eloquent
Laravel MPdf : Easily generate PDF files with arabic support
Szamlazz.hu integration for Laravel
Modern PHP 8.3+ BOLT 11 Lightning Network invoice encoder/decoder
Provides TCPDF integration for Symfony
A package for easy integration between Laravel applications and Autentique's digital signature service.
统计信息
- 总下载量: 903
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 23
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-07-02