PHP code example of typesetsh / pdf-bundle

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

    

typesetsh / pdf-bundle example snippets


return [
    // [...]
    Typesetsh\PdfBundle\TypesetshPdfBundle::class => ['all' => true],
];



namespace App\Controller;

use Symfony\Component\HttpFoundation\HeaderUtils;
use Typesetsh\PdfBundle;

class TestController extends PdfBundle\Controller\AbstractController
{
    public function printOrder()
    {
        $order = new \stdClass();

        return $this->pdf(
            'pdf/invoice.html.twig',
            ['order' => $order],
            'test.pdf',
            HeaderUtils::DISPOSITION_INLINE
        );
    }
}



use Typesetsh\PdfBundle\PdfGenerator;

class PrintService
{
    /** @var PdfGenerator */
    private $pdfGenerator;

    public function __construct(PdfGenerator $pdfGenerator)
    {
        $this->pdfGenerator = $pdfGenerator;
    }

    public function execute()
    {
        $html = '...';

        $result = $this->pdfGenerator->render($html);
        $result->toFile('./somefile.pdf');
        $result->asString();

    }
}