1. Go to this page and download the library: Download tklaversma/flexpdf 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/ */
tklaversma / flexpdf example snippets
use FlexPDF\Facades\Pdf;
Pdf::view('invoices.show', ['invoice' => $invoice])->download('invoice.pdf');
use FlexPDF\Facades\Pdf;
class InvoiceController extends Controller
{
public function download(Invoice $invoice)
{
return Pdf::view('invoices.show', ['invoice' => $invoice])
->download("invoice-{$invoice->number}.pdf");
}
}
Pdf::view('invoices.show', ['invoice' => $invoice]) // a Blade view, like view()
Pdf::html('<h1>Hello</h1>') // an HTML string you already have
Pdf::loadFile(resource_path('templates/report.html')) // an HTML file on disk
->download('invoice.pdf') // browser shows a save dialog
->inline('invoice.pdf') // opens right in the browser tab
->save(storage_path('app/invoices/invoice.pdf')) // write to disk
->output() // the raw bytes, when you need them yourself
// Store on disk
Storage::disk('s3')->put(
'invoices/invoice.pdf',
Pdf::view('invoices.show', $data)->output()
);
// Use in a Mailable
$this->attachData(
Pdf::view('invoices.show', $data)->output(),
'invoice.pdf',
['mime' => 'application/pdf']
);
Pdf::view('report')
->page('a4') // a3, a4, a5, letter, legal, tabloid, or [w, h] in points
->landscape()
->margins(40, 30) // top/bottom, left/right (CSS shorthand order)
->header('<div>Quarterly report</div>')
->footer('<div>Page {page} of {pages}</div>')
->inline('report.pdf');
Pdf::view('report')
->metadata(['title' => 'Q3 Report', 'author' => 'Acme B.V.'])
->initialView('FitH', page: 1) // how the reader opens the document
->pageMode('UseOutlines') // with the bookmarks panel showing
->save($path);
Pdf::view('invoices.show', $data)
->tagged(lang: 'en') // tagged PDF: a real structure tree and /Lang
->pdfa() // PDF/A-3 (ISO 19005-3), level B, or 'A'
->pdfua() // claim PDF/UA-1 (ISO 14289-1) as well
->save($path);