PHP code example of rarog / dompdf-helper

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

    

rarog / dompdf-helper example snippets


     'DompdfHelper',
     



namespace My\Factory\Controller;

use Interop\Container\ContainerInterface;
use My\Controller\ExampleController;

class ExampleControllerFactory implements FactoryInterface
{
    /**
     * {@inheritDoc}
     * @see \Laminas\ServiceManager\Factory\FactoryInterface::__invoke()
     */
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
    {
        return new ExampleController(
            $container->get('dompdf')
        );
    }
}



namespace My\Controller;

use Dompdf\Dompdf;
use Laminas\Mvc\Controller\AbstractActionController;

class ExampleController extends AbstractActionController
{
    /**
     * @var Dompdf
     */
    private $dompdf;

    /**
     * Constructor
     *
     * @param Dompdf $dompdf
     */
    public function __construct(
        Dompdf $dompdf
    ) {
        $this->dompdf = $dompdf;
    }

    public function indexAction()
    {
        $this->dompdf->load_html('<strong>Hello World</strong>');
        $this->dompdf->render();

        file_put_contents(__DIR__ . '/document.pdf', $this->dompdf->output());
    }
}