PHP code example of trianity / laravel-mpdf

1. Go to this page and download the library: Download trianity/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/ */

    

trianity / laravel-mpdf example snippets


use Trianity\LaravelMpdf\LaravelMpdfWrapper;

public function show(LaravelMpdfWrapper $pdf)
{
    return $pdf->loadHTML('<h1>Hello</h1>')->output();
}

use Trianity\LaravelMpdf\Facades\PDF;

class ReportController
{
    public function show()
    {
        $pdf = PDF::loadView('pdf.document', ['name' => 'World']);

        $pdf->stream('document.pdf');
    }
}

PDF::loadHTML('<h1>Hello</h1>');
PDF::loadFile(storage_path('app/document.html'));
PDF::loadView('pdf.document', $data);

PDF::chunkLoadHTML($html, '<html-separator/>');
PDF::chunkLoadFile($file, '<html-separator/>');
PDF::chunkLoadView('pdf.document', '<html-separator/>', $data);

$pdf->output();                         // Return the PDF as a string
$pdf->save($path);                      // Save the PDF and return $path
$pdf->download('document.pdf');         // Send it as a download
$pdf->stream('document.pdf');           // Send it inline
$pdf->getMpdf()->AddPage();             // Access the underlying mPDF instance
$pdf->WriteHTML('<p>More HTML</p>');

$pdf = PDF::loadView('pdf.document', $data, [], [
    'format' => 'A5',
    'orientation' => 'L',
    'title' => 'Another title',
]);

return [
    'custom_font_dir' => base_path('resources/fonts'),
    'custom_font_data' => [
        'examplefont' => [
            'R' => 'ExampleFont-Regular.ttf',
            'B' => 'ExampleFont-Bold.ttf',
            'I' => 'ExampleFont-Italic.ttf',
            'BI' => 'ExampleFont-Bold-Italic.ttf',
        ],
    ],
];
bash
php artisan vendor:publish --tag=mpdf-config