PHP code example of websolutionstuff / pdf-laravel

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

    

websolutionstuff / pdf-laravel example snippets


'providers' => [
    ...
    ...
    Websolutionstuff\PDF\ServiceProvider::class
]

//...

'aliases' => [
    ...
    ..
    'PDF' => Websolutionstuff\PDF\Facades\PDF::class
]

$app->register(Websolutionstuff\PDF\ServiceProvider::class);
class_alias(Websolutionstuff\PDF\Facades\PDF::class, 'PDF');

use PDF; // at the top of the file

  PDF::SetTitle('Websolutionstuff PDF File');
  PDF::AddPage();
  PDF::Write(0, 'Websolutionstuff PDF File Generate');
  PDF::Output('websolutionstuff.pdf');

use PDF; // at the top of the file

  for ($i = 0; $i < 5; $i++) {
    PDF::SetTitle('Websolutionstuff PDF File'.$i);
    PDF::AddPage();
    PDF::Write(0, 'Websolutionstuff PDF File Generate'.$i);
    PDF::Output(public_path('websolutionstuff' . $i . '.pdf'), 'F');
    PDF::reset();
  }

        $html = '<h1 style="color:red;">Hello World</h1>';
        
        PDF::SetTitle('Hello World');
        PDF::AddPage();
        PDF::writeHTML($html, true, false, true, false, '');
        PDF::Output('Example_1.pdf');

        // remove default header/footer
        PDF::setPrintHeader(false);
        PDF::setPrintFooter(false);
        
        // set margins
        PDF::SetMargins(20,20,20);

        // set auto page breaks
        PDF::SetAutoPageBreak(TRUE, 20);

        // set font
        PDF::SetFont('times', 'BI', 20);

        // add a page
        PDF::AddPage();

        // set some text to print
        $txt = <<<EOD
        PDF Example 2

        Default page header and footer are disabled using setPrintHeader() and setPrintFooter() methods.
        EOD;

        // print a block of text using Write()
        PDF::Write(0, $txt, '', 0, 'C', true, 0, false, false, 0);        

        //Close and output PDF document
        PDF::Output('example_2.pdf', 'I');