library zend-pdf
Create pdf from view in zend framework 2
takeoo/zend-pdf
Create pdf from view in zend framework 2
- Tuesday, July 4, 2017
- by TakeoO
- Repository
- 1 Watchers
- 0 Stars
- 1,434 Installations
- PHP
- 0 Dependents
- 0 Suggesters
- 0 Forks
- 0 Open issues
- 5 Versions
- 19 % Grown
HTML to PDF for zend framework
Create pdf from view in ZendFramework 3, (*1)
Works on zend framework v3.*, (*2)
IF you want to use it with older versions, use one of previous tags, (*3)
Requirements
Install
-
Composer install
bash
composer require takeoo/zend-pdf
, (*8)
-
Add "Takeoo\Pdf" to 'modules' array in application.config.php, (*9)
Usage
-
Takeoo\Zend-pdf will create service throughout service manager, so it is available in serviceLocator as 'PdfCreator';, (*10)
-
Instantiate:, (*11)
$pdfCreator = $serviceManager->get('PdfCreator');
NOTE: PdfCreator is not shared service, so every call to serviceManager will create new instance., (*12)
PdfCreator uses ViewResolver which is auto-magically injected to PhpRenderer if have MVC application, so you can use any view or layout you have in your app!, (*13)
-
Set layout, (*14)
$pdfCreator->setLayoutTemplate('layout/pdf-template');
- Add view as you would in your response, just pass name and variables to createHtml() function
$pdfCreator->createHtml('path/to/view', ['variableName' => $variableValue]);
OR you can directly pass already created view model, (*15)
$pdfCreator->createHtmlFromViewModel($viewModel);
-
Output, (*16)
NOTE: Both above functions will save file to your disk, (*19)
-
Get file path, (*20)
$pdfCreator->getFilePath();
-
By default all files are generated to your project root into "{Ymd_His}.pdf", (*21)
-
Change file destination, (*22)
$pdfCreator->setPdfFileName('path/to/desired/folder/nameofyourfile.pdf');
NOTE: All functions with public scope (with exception of output() and writePdf()) are fluent, so you can chain all functions:, (*23)
$pdfCreator->setLayoutTemplate('layout/pdf-layout')
->createHtml('view', ['variable1' => $variable1Value])
->setPdfFileName('./../file.pdf')
->setHasXvfb(false)
->output();
NOTE: By default all wkhtmltopdf conversions are created with setHasXvfb(true), so you have to have installed Xvfb on your server!
If you want to turn it of just do:, (*24)
$pdfCreator->setHasXvfb(false);
dev-master
9999999-dev
Create pdf from view in zend framework 2
Sources
Download
The Requires
by
Jan Mrhar
v0.2.1
0.2.1.0
Create pdf from view in zend framework 2
Sources
Download
The Requires
by
Jan Mrhar
v0.2.0
0.2.0.0
Create pdf from view in zend framework 2
Sources
Download
The Requires
by
Jan Mrhar
v0.1.1
0.1.1.0
Create pdf from view in zend framework 2
Sources
Download
The Requires
by
Jan Mrhar
v0.1.0
0.1.0.0
Create pdf from view in zend framework 2
Sources
Download
The Requires
by
Jan Mrhar