PHP code example of vzool / laravel-pdf
1. Go to this page and download the library: Download vzool/laravel-pdf 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/ */
vzool / laravel-pdf example snippets
'providers' => [
// ...
vzool\LaravelPdf\PdfServiceProvider::class
]
'aliases' => [
// ...
'PDF' => vzool\LaravelPdf\Facades\Pdf::class
]
use PDF;
function generate_pdf() {
$data = [
'foo' => 'bar'
];
$pdf = PDF::loadView('pdf.document', $data);
return $pdf->stream('document.pdf');
}
return [
'mode' => '',
'format' => 'A4',
'defaultFontSize' => '12',
'defaultFont' => 'sans-serif',
'marginLeft' => 10,
'marginRight' => 10,
'marginTop' => 10,
'marginBottom' => 10,
'marginHeader' => 0,
'marginFooter' => 0,
'orientation' => 'P',
'title' => 'Laravel PDF',
'author' => '',
'watermark' => '',
'showWatermark' => false,
'watermarkFont' => 'sans-serif',
'SetDisplayMode' => 'fullpage',
'watermarkTextAlpha' => 0.1
];
return [
'custom_font_path' => base_path('/resources/fonts/'), // don't forget the trailing slash!
'custom_font_data' => [
'examplefont' => [
'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;
function generate_pdf() {
$data = [
'foo' => 'bar'
];
$pdf = PDF::loadView('pdf.document', $data);
$pdf->SetProtection(['copy', 'print'], '', 'pass');
return $pdf->stream('document.pdf');
}