Download the PHP package xslain/html2media without Composer
On this page you can find all versions of the php package xslain/html2media. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download xslain/html2media
More information about xslain/html2media
Files in xslain/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 provides seamless integration with Livewire components, enabling dynamic content rendering 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 Livewire Component Documentation π
Html2Media is a powerful Laravel Livewire package that allows you to generate PDFs, preview documents, and directly print content from your application. π
π Overview
The Html2Media package provides flexible Livewire components for your Laravel applications, 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 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.
- β‘ Livewire Integration: Seamless integration with Livewire components and events.
π§ Installation
To install the package, simply run the following command:
After installation, publish the assets:
The Html2Media components will be automatically registered with Livewire.
π Basic Usage
Method 1: Using the Livewire Component
You can use the Html2Media Livewire component directly in your Blade templates:
Method 2: Using the Button Component
For a simple button that triggers PDF generation:
Method 3: Creating Custom Livewire Components
Create your own Livewire component that uses the Html2Media trait:
βοΈ Configuration Methods
Here's how you can customize your Html2Media components!
1. π filename()
Set the name of the generated PDF file. βοΈ
Usage:
- π·οΈ Default:
'document.pdf' - π Accepts:
stringorClosure
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(e.g.,'a4','letter') orarrayfor custom dimensions, plusunitparameter
5. π scale()
Control the rendering quality of the PDF by adjusting the scale factor. π
Usage:
- π·οΈ Default:
2 - π Accepts:
intorClosure
6. π margin()
Set the margins for the PDF document. π
Usage:
- π·οΈ Default:
0 - π Accepts:
int(uniform margin) orarray([top, right, bottom, left]) orClosure
7. π enableLinks()
Enable or disable PDF hyperlinks. When enabled, hyperlinks are automatically added on top of all anchor tags. π
Usage:
- π·οΈ Default:
false - π Accepts:
boolorClosure
8. π» content()
Set the content for the document. Typically, you'll pass a Blade view for the content. π
Usage:
- π Accepts:
View,Htmlable, orClosure
π¨ Complete Example
Here's a complete example of a custom Livewire component with Html2Media:
Corresponding Blade template (livewire/report-generator.blade.php):
β‘ Quick Examples
1. Simple PDF Download Button:
2. Multi-action Component:
π Requirements
- PHP: ^8.1, ^8.2, or ^8.3
- Laravel: ^10.0, ^11.0, or ^12.0
- Livewire: ^3.0
π Conclusion
The Html2Media package for Livewire makes it easy to generate PDFs, preview documents, and print content directly from your Laravel app. With flexible configuration options and seamless Livewire integration, you can tailor it to your specific needs, ensuring smooth document handling. β¨
We hope this documentation helps you get started quickly. π Happy coding! π
- π·οΈ Default:
'document.pdf' - π Accepts:
stringorClosure
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:
boolorClosure
6. π§ scale()
Adjust the scaling factor for HTML to PDF conversion. π
Usage:
- π·οΈ Default:
2 - π Accepts:
intorClosure
7. π¨οΈ print()
Enable or disable the print button in the modal. π¨οΈ
Usage:
- π·οΈ Default:
true - π Accepts:
boolorClosure
8. ποΈ preview()
Enable a preview option for the document content before printing or saving. π
Usage:
- π·οΈ Default:
false - π Accepts:
boolorClosure
9. πΎ savePdf()
Enable the option to directly save the content as a PDF. πΎ
Usage:
- π·οΈ Default:
false - π Accepts:
boolorClosure
10. β
requiresConfirmation()
Show a confirmation modal before performing the action. π
Usage:
- π·οΈ Default:
true - π Accepts:
boolorClosure
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
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.
π Livewire Component Usage
You can use the Html2Media components in various ways throughout your Livewire application. Here are the available components:
This makes the package flexible and usable in various contexts throughout your Laravel application. π
β‘ Quick Examples
- 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 Livewire 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! π
All versions of html2media with dependencies
illuminate/support Version ^10.0|^11.0|^12.0
illuminate/contracts Version ^10.0|^11.0|^12.0
livewire/livewire Version ^3.0
spatie/laravel-package-tools Version ^1.13