Pdf Generation

To generate PDF from HTML and CSS you just need to pass the entire HTML and CSS to the pdf generator. To allow for easy switching between rendering engines we support multiple ways of generating PDFs and they can be switched between via the configuration.

Example Code


use Parthenon\Common\Pdf\GeneratorInterface;

function pdfGenerate(GeneratorInterface $generator)
{
  $pdf = $generator->generate('<b>HELLO WORLD</b>');

}

Configuration

All these configurations are under the parthenon.common configuration section.

| name | default | description | | generator | null | What PDF generation method should be used. wkhtmltopdf, docraptor, mpdf | | wkhtmltopdf.bin | /usr/bin/wkhtmltopdf | The location of the wkhtmltopdf | | docraptor.api_key | null | The API key to be used with docraptor | | mpdf.tmp_dir | /tmp | The temporary directory that mpdf should use. |

Example

parthenon:
  common:
    pdf:
    generator: 'mpdf'
    mpdf:
      tmp_dir: '/tmp'  
    wkhtmltopdf:
      bin: '/usr/bin/wkhtmltopdf'
    docraptor:
      api_key: 'docraptor-api-key'  

Snappy/wkhtmltopdf

Snappy is a library to wrap the wkhtmltopdf. This allows generating pdfs using wkhtmltopdf and requires that wkhtmltopdf is install locally on the web server.

To install the snappy library you need to run:

composer require knplabs/knp-snappy

DocRaptor

Due to an issue with the offical DocRaptor API sdk not supporting the latest Guzzle and therefore not PHP 8, to work around this we’ve forked the repository and made the change to allow it to work with PHP 8.

To install our fork you need to run:

composer require parthenon/docraptor

MPDF

To install the mpdf library you need to run:

composer require mpdf/mpdf