Download the PHP package torgodly/html2media without Composer
On this page you can find all versions of the php package torgodly/html2media. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download torgodly/html2media
More information about torgodly/html2media
Files in torgodly/html2media
Package html2media
Short Description 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 orientation, format, margins, and scale. Html2Media also provides seamless integration with Filament actions, enabling dynamic content rendering in modals and customizable output previews. Whether you need to save a PDF or send it directly to the printer, Html2Media simplifies the process with robust, flexible features.
License MIT
Informations about the package html2media
π Html2Media Filament Action Documentation π
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:
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:
- π·οΈ Default:
'document.pdf'
- π Accepts:
string
orClosure
2. π pagebreak()
Define page break behavior. Customize how and where page breaks occur within the document. π
Usage:
- π 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:
- π·οΈ Default:
'portrait'
- π Accepts:
string
('portrait'
,'landscape'
) orClosure
4. π format()
Define the format of the PDF, including standard sizes like A4 or custom dimensions. π
Usage:
- π·οΈ Default:
'a4'
- π Accepts:
string
,array
(e.g.,[width, height]
), orClosure
5. π enableLinks()
Enable or disable automatic hyperlink conversion in the PDF. π
Usage:
- π·οΈ Default:
false
- π Accepts:
bool
orClosure
6. π§ scale()
Adjust the scaling factor for HTML to PDF conversion. π
Usage:
- π·οΈ Default:
2
- π Accepts:
int
orClosure
7. π¨οΈ print()
Enable or disable the print button in the modal. π¨οΈ
Usage:
- π·οΈ Default:
true
- π Accepts:
bool
orClosure
8. ποΈ preview()
Enable a preview option for the document content before printing or saving. π
Usage:
- π·οΈ Default:
false
- π Accepts:
bool
orClosure
9. πΎ savePdf()
Enable the option to directly save the content as a PDF. πΎ
Usage:
- π·οΈ Default:
false
- π Accepts:
bool
orClosure
10. β
requiresConfirmation()
Show a confirmation modal before performing the action. π
Usage:
- π·οΈ Default:
true
- π Accepts:
bool
orClosure
11. π» content()
Set the content for the document. Typically, youβll pass a Blade view for the content. π
Usage:
- π Accepts:
View
,Htmlable
, orClosure
π¨ Example Usage
Hereβs a complete example of configuring the Html2MediaAction:
This configuration will:
- π Generate a PDF from the
invoice
Blade view. - π¨οΈ Allow users to
preview
andprint
the document. - πΎ Enable
saving as PDF
and 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:
This makes the action flexible and usable in various contexts. π
β‘ Quick Example: Direct Print or Save as PDF
- For direct printing:
This will directly open the print dialog for the HTML content. π¨οΈ
- For saving as PDF:
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! π