mPDF (Advanced PDF Generator)
The artiframe add mpdf command installs the mpdf/mpdf package, one of the most capable and well-established HTML-to-PDF conversion tools in the PHP world.
It is particularly successful with invoice layouts, complex tables, and UTF-8 (special character) support.
💡 Information: Direct Usage
ArtiFrame does not copy a specific integration (Wrapper/Stub) class to the
ArtiFrame does not copy a specific integration (Wrapper/Stub) class to the
src/Service folder for this package. The installation simply includes the package into the project via Composer.
The codes below are basic usage examples demonstrating the package's native operations. For more information, please review the mPDF Documentation.
Installation
terminal
$ artiframe add mpdf
Usage Example
You can use it directly by initializing the \Mpdf\Mpdf object inside any Controller or Service.
InvoiceController.php
<?php
use Mpdf\Mpdf;
// 1. Initialize a new PDF instance (UTF-8 and A4 format are default)
$mpdf = new Mpdf([
'mode' => 'utf-8',
'format' => 'A4',
'margin_top' => 20
]);
// 2. Prepare your HTML content
$html = '
<h1>Monthly Account Statement</h1>
<p>Dear customer, here are your expenses for this month:</p>
<table border="1" cellpadding="10">
<tr>
<th>Product</th>
<th>Price</th>
</tr>
<tr>
<td>Premium Membership</td>
<td>$15.00</td>
</tr>
</table>
';
// 3. Write HTML to mPDF
$mpdf->WriteHTML($html);
// 4. Output (Show in Browser, Download, or Save to Disk)
// Option A: Opens as PDF in the browser
$mpdf->Output('invoice.pdf', \Mpdf\Output\Destination::INLINE);
// Option B: Forces download to the browser
// $mpdf->Output('invoice.pdf', \Mpdf\Output\Destination::DOWNLOAD);
// Option C: Saves as a physical file on the server
// $mpdf->Output(__DIR__ . '/../../storage/invoices/invoice.pdf', \Mpdf\Output\Destination::FILE);