vladmeh / zf3-tcpdf
A Zend Framework 3 module for incorporating TCPDF support.
Installs: 31 759
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 3
Forks: 2
Open Issues: 0
Requires
- php: ^5.6 || ^7.0
- tecnickcom/tcpdf: ^6.2
- zendframework/zend-mvc: ^3.0
This package is auto-updated.
Last update: 2025-02-14 00:55:57 UTC
README
A Zend Framework 3 module for incorporating TCPDF support.
Requirements
- Zend Faramework 3
- PHP v5.6 or 7.0
Installation
-
Installation of TCPDFModule uses PHP Composer. For more information about PHP Composer, please visit the official PHP Composer site.
php composer.phar require vladmeh/zf3-tcpdf
-
Open my/project/directory/config/modules.config.php and add the following key to your modules:
return [ ... 'TCPDFModule', ];
Example usage
// module config: module\Application\config\module.config.php <?php namespase Application; use Application\Factory\IndexControllerFactory; return [ 'controllers' => [ 'factories' => [ Controller\IndexController::class => IndexControllerFactory::class, ], ], 'router' => [], ... ];
// module\Application\src\Factory\IndexControllerFactory.php <?php namespace Application\Factory; use Application\Controller\IndexController; use Interop\Container\ContainerInterface; use Zend\ServiceManager\Factory\FactoryInterface; use Zend\View\Renderer\RendererInterface; class IndexControllerFactory implements FactoryInterface { public function __invoke(ContainerInterface $container, $requestedName, array $options = null) { $tcpdf = $container->get(\TCPDF::class); $renderer = $container->get(RendererInterface::class); return new IndexController( $tcpdf, $renderer ); } }
// module\Application\src\Controller\IndexController.php <?php namespace Application\Controller; use Zend\Mvc\Controller\AbstractActionController; use Zend\View\Model\ViewModel; use Zend\View\Renderer\RendererInterface; class IndexController extends AbstractActionController { /** * @var \TCPDF */ protected $tcpdf; /** * @var RendererInterface */ protected $renderer; public function __construct($tspdf, $renderer) { $this->tcpdf = $tspdf; $this->renderer = $renderer; } public function indexAction() { $view = new ViewModel(); $renderer = $this->renderer; $view->setTemplate('layout/pdf'); $html = $renderer->render($view); $pdf = $this->tcpdf; $pdf->SetFont('arialnarrow', '', 12, '', false); $pdf->AddPage(); $pdf->writeHTML($html, true, false, true, false, ''); $pdf->Output(); } }