rarog / dompdf-helper
DompdfHelper - a lightweight library wrapper Laminas module
Requires
- php: ^8.0
- dompdf/dompdf: ^2.0
- laminas/laminas-modulemanager: ^2.10
- laminas/laminas-servicemanager: ^3.6
Requires (Dev)
- php-coveralls/php-coveralls: ^2.0
- phpunit/phpunit: ^9.0
- squizlabs/php_codesniffer: ^3.6
README
DompdfHelper - a lightweight library wrapper Laminas module
Requirements
Installation
Installation of DompdfHelper uses PHP Composer. For more information about PHP Composer, please visit the official PHP Composer site.
Installation steps
-
cd my/project/directory
-
create a
composer.json
file with following contents:{ "require": { "rarog/dompdf-helper": "^4.0" } }
-
install PHP Composer via
curl -s http://getcomposer.org/installer | php
(on windows, download http://getcomposer.org/installer and execute it with PHP) -
run
php composer.phar install
-
open
my/project/directory/config/application.config.php
and add the following key to yourmodules
:'DompdfHelper',
Configuration options
You can override default options via the dompdf
key in your local or global config files. See the config/dompdf.config.php.dist file for the list of default settings.
Full list of possible settings is available at the official Dompdf library site.
Example usage
Controller factory
<?php 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') ); } }
Controller
<?php 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()); } }