PHP code example of barryvdh / laravel-dompdf

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

    

barryvdh / laravel-dompdf example snippets


    use Barryvdh\DomPDF\Facade\Pdf;

    $pdf = Pdf::loadView('pdf.invoice', $data);
    return $pdf->download('invoice.pdf');

    $pdf = App::make('dompdf.wrapper');
    $pdf->loadHTML('<h1>Test</h1>');
    return $pdf->stream();

    return Pdf::loadFile(public_path().'/myfile.html')->save('/path-to/my_stored_file.pdf')->stream('download.pdf');

    Pdf::loadHTML($html)->setPaper('a4', 'landscape')->setWarnings(false)->save('myfile.pdf')

    Pdf::setOption(['dpi' => 150, 'defaultFont' => 'sans-serif']);

    'pdfa' => [
        'enabled' => true,
    ],

    $pdf = Pdf::loadView('invoice', $data)
        ->setPdfA()
        ->download('invoice.pdf');

    $pdf = Pdf::loadView('invoice', $data)->setPdfA();

    // Add XMP metadata for Factur-X
    $pdf->setAdditionalXmpRdf(
        '<rdf:Description rdf:about=""
            xmlns:fx="urn:factur-x:pdfa:CrossIndustryDocument:invoice:1p0#">
            <fx:DocumentType>INVOICE</fx:DocumentType>
            <fx:DocumentFileName>factur-x.xml</fx:DocumentFileName>
            <fx:Version>1.0</fx:Version>
            <fx:ConformanceLevel>BASIC</fx:ConformanceLevel>
        </rdf:Description>'
    );

    // Embed the XML invoice
    $pdf->addEmbeddedFile(
        storage_path('invoices/factur-x.xml'),
        'factur-x.xml',
        'Factur-X Invoice',
        'text/xml'
    );

    return $pdf->download('invoice.pdf');
shell
    php artisan vendor:publish --provider="Barryvdh\DomPDF\ServiceProvider"