PHP code example of peterbenke / pb-pdf

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

    

peterbenke / pb-pdf example snippets



namespace [YourVendor]\[YourExtension]\[...];


use PeterBenke\Pdf\Service\PdfService;
use TYPO3\CMS\Core\Utility\GeneralUtility;


class YourClass
{

  public function yourFunction()
  {
  
  
    $absoluteJobPdfPath = '/var/www/html/fileadmin/user_upload/your-pdf-file.pdf';
    $assign = [];
  
    // Create instance
  
    /** @var PdfService $pdfService */
    $pdfService = GeneralUtility::makeInstance(
        PdfService::class,
        'your_extension_key', // extension key
        '/Resources/Private/Templates/Pdf/your-template.html', // template path
        $absoluteJobPdfPath,  // absolute! pdf path to pdf file
        null,                 // tmp directory, if empty => '/tmp' will be set
        $assign               // optional assign array (fluid)
    );
    
    // Create pdf file
    
    try{
        $pdfService->create();
    }catch(Exception $e){
        echo $e->getMessage();
    }
    
  
  }

}