PHP code example of tklaversma / flexpdf

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')
    ->header(fn (int $page): ?string => $page === 1
        ? null
        : '<div>Quarterly report</div>')
    ->footer(fn (int $page, int $total): ?string => $page === $total
        ? '<div>End of report</div>'
        : '<div>{page} / {pages}</div>')
    ->inline('report.pdf');

'fonts' => [
    'Inter' => [
        'regular'     => resource_path('fonts/Inter-Regular.ttf'),
        'bold'        => resource_path('fonts/Inter-Bold.ttf'),
        'italic'      => resource_path('fonts/Inter-Italic.ttf'),
        'bold-italic' => resource_path('fonts/Inter-BoldItalic.ttf'),
    ],
],

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);

Pdf::view('payslip', $data)
    ->encrypt('user-password', allow: ['print'])
    ->download('payslip.pdf');

Pdf::view('invoices.show', $data)
    ->pdfa()
    ->attach('factur-x.xml', $xml, 'text/xml', 'Invoice data', 'Data')
    ->save($path);

'limits' => [
    'max_pages'          => 2000,
    'max_depth'          => 64,
    'max_length'         => 200000.0,
    'max_font_size'      => 2000.0,
    'timeout_seconds'    => 30.0,
    'max_gradient_stops' => 500000,
    'max_image_bytes'    => 200_000_000,
],

'remote_images' => [
    'enabled'       => true,
    'allowed_hosts' => ['cdn.example.com'],
    'max_bytes'     => 2_000_000,
    'timeout'       => 5.0,
],
bash
php artisan vendor:publish --tag="flexpdf-config"
bash
php tests/Engine/fuzz.php <seed> <iterations>