2017 © Pedro Peláez
 

library html-to-pdf-bundle

A SF2 bundle to easely handle pdf generation and merge with wkhtmltopdf

image

jihel/html-to-pdf-bundle

A SF2 bundle to easely handle pdf generation and merge with wkhtmltopdf

  • Tuesday, March 27, 2018
  • by Jihel
  • Repository
  • 1 Watchers
  • 0 Stars
  • 371 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 37 % Grown

The README.md

HtmlToPdfBundle

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)

1- Install

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(),
    );
}

2- Configure your config.yml

The default configuration file and explanations can be found here, (*6)

3- Usage

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)

4- Note

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)

5- Thanks

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)

The Versions

27/03 2018

dev-master

9999999-dev

A SF2 bundle to easely handle pdf generation and merge with wkhtmltopdf

  Sources   Download

The Requires

 

by Joseph Lemoine