surda/pdf

v2.0.0 2021-04-03 18:56 UTC

This package is auto-updated.

Last update: 2024-10-29 05:28:48 UTC


README

Build Status Licence Latest stable PHPStan

Installation

The recommended way to is via Composer:

composer require surda/pdf

After that you have to register extension in config.neon:

extensions:
    pdf: Surda\Pdf\DI\PdfExtension

Configuration

Default

pdf:
    template:
        defaults:
            layout: @@default
        config:
            layout: @@default

Usage

Builder

/** @var Surda\Pdf\IPdfBuilderFactory @inject */
public $pdfBuilderFactory;
// Builder
$builder = $this->pdfBuilderFactory->create();

// Template
$builder->setTemplateFile(__DIR__ . '/path/to/template.latte');
$builder->setParameters([
    'foo' => 'World!',
]);

// Get Mpdf
$mpdf = $builder->getMpdf();

$this->sendResponse(new PdfResponse($mpdf->Output('file.pdf', \MPdf\Output\Destination::DOWNLOAD)));

Template

Each template has many internal variables:

  • $_defaults - refer default configuration
  • $_config - refer custom configuration
{layout defaults->layout}

{block #content}
    Hello, {$foo}
{/block}