1. Go to this page and download the library: Download carlos-meneses/laravel-mpdf library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use PDF;
$pdf = PDF::loadView('pdf.document', $data);
$pdf->getMpdf()->AddPage(/*...*/);
return [
'custom_font_dir' => base_path('resources/fonts/'), // don't forget the trailing slash!
'custom_font_data' => [
'examplefont' => [ // must be lowercase and snake_case
'R' => 'ExampleFont-Regular.ttf', // regular font
'B' => 'ExampleFont-Bold.ttf', // optional: bold font
'I' => 'ExampleFont-Italic.ttf', // optional: italic font
'BI' => 'ExampleFont-Bold-Italic.ttf' // optional: bold-italic font
]
// ...add as many as you want.
]
];
//....
use PDF;
class ReportController extends Controller
{
public function generate_pdf()
{
$data = [
'foo' => 'hello 1',
'bar' => 'hello 2'
];
$pdf = PDF::chunkLoadView('<html-separator/>', 'pdf.document', $data);
return $pdf->stream('document.pdf');
}
}
//...
use Mccarlosen\LaravelMpdf\LaravelMpdf;
class AppServiceProvider extends ServiceProvider
{
//...
public function boot()
{
LaravelMpdf::macro('hello', function () {
return "Hello, World!";
});
}
//...
}
PDF::loadView(/* ... */)->hello();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.