dev-master
9999999-devA SF2 bundle to easely handle pdf generation and merge with wkhtmltopdf
The Requires
- php >=5.3.3
- symfony/symfony >=2.3
by Joseph Lemoine
Wallogit.com
2017 © Pedro Peláez
A SF2 bundle to easely handle pdf generation and merge with wkhtmltopdf
A SF2 bundle to easily handle pdf generation and concatenation with wkhtmltopdf and pdftk This bundle only provide a php object way to g, basically it will simply execute the command. If you need some particular feature, you should create your own command abstraction class., (*1)
Add plugin to your composer.json require:, (*2)
{
"require": {
"jihel/html-to-pdf-bundle": "dev-master",
}
}
or, (*3)
php composer.phar require jihel/html-to-pdf-bundle:dev-master
Install packages binaries:, (*4)
aptitude install wkhtmltopdf pdftk xvfb
Add bundle to your AppKernel.php, (*5)
public function registerBundles()
{
$bundles = array(
...
new Jihel\Plugin\HtmlToPdfBundle\JihelPluginHtmlToPdfBundle(),
);
}
The default configuration file and explanations can be found here, (*6)
Get the generator service jihel.plugin.html_to_pdf.generator.pdf:, (*7)
From a controller, (*8)
/** @var \Jihel\Plugin\HtmlToPdfBundle\Generator\PdfGenerator $pdfGenerator */ $pdfGenerator = $this->get('jihel.plugin.html_to_pdf.generator.pdf');, (*9)
From a service, (*10)
service: my.super.pdf.service: class: %my.super.mdf.service.class% arguments: { '@jihel.plugin.html_to_pdf.generator.pdf' }, (*11)
The class provite two methods, one to generate a pdf from a template name and datas, and the other to concatenate all pages from pdf files in an array list or a folder., (*12)
/** * Create a .pdf file from the given $template name with given $data parameters * * @param string $template * @param array $data * @return \SplFileObject */ public function create($template, array $data = array()) /** * Concatenate the given pdf files. * If you provide a path a folder, * concatenate them by alphabetic order * * @param \SplFileObject[]|string $files * @param bool $unlink * @return \SplFileObject * @throws Exception\NotASplFileObjectException */ public function concatenate($files, $unlink = false)
Both will return an SplFileObject temporally saved in the /tmp folder., (*13)
You can read execution messages with the methods :, (*14)
public function getLastConcatenateCommandResult() public function getLastCreateCommandResult()
Only the last executed command output will be visible. Think about the verbose option to have more details., (*15)
The use_xvfb option is resources consuming. Think about using wkhtmltopdf on a server
with a permanent xserver running., (*16)
If you want to include background pictures, put the absolute path in your $data array., (*17)
Thanks to Romain Sebille (Give me your email man !) who made the research and the first iteration of the command generator. Thanks to my cat to keep meowing me. Thanks to me for giving my free time doing class for lazy developers. You can access read CV here, (*18)
A SF2 bundle to easely handle pdf generation and merge with wkhtmltopdf