PHP code example of zanysoft / laravel-pdf

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

    

zanysoft / laravel-pdf example snippets


'providers' => [
	// ...
	ZanySoft\LaravelPDF\PdfServiceProvider::class
]

'aliases' => [
	// ...
	'PDF' => ZanySoft\LaravelPDF\Facades\PDF::class
]

use PDF;

function generate_pdf() {
	$data = [
		'foo' => 'bar'
	];
	$pdf = PDF::::Make();
	$pdf->loadView('pdf.document', $data);
	return $pdf->stream('document.pdf');
}

use ZanySoft\LaravelPDF\PDF;

function generate_pdf() {
	$data = [
		'foo' => 'bar'
	];
	$pdf = new PDF();
	$pdf->loadView('pdf.document', $data);
	return $pdf->stream('document.pdf');
}


    $content = "Hello this is first pdf file."
	$pdf->loadHTML($content);
	return $pdf->stream('document.pdf');

    $file = "file.txt"
	$pdf->loadFile($file);
	return $pdf->stream('document.pdf');

	return $pdf->embed('document.pdf');

	return $pdf->save('with-complete-path/document.pdf');

	return $pdf->embed('document.pdf');

    return [
	    'custom_font_path' => base_path('/resources/fonts/'), // don't forget the trailing slash!
    ];

    $font_data = array(
        '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.
    );

	$pdf->addCustomFont($font_data, true);
	// If your font file is unicode and "OpenType Layout" then set true. Default value is false.

use PDF;

function generate_pdf() {
	$data = [
		'foo' => 'bar'
	];
	$pdf = PDF::Make();
	$pdf->SetProtection(['copy', 'print'], 'user_pass', 'owner_pass')
	$pdf->loadView('pdf.document', $data);

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