2017 © Pedro Peláez
 

symfony-bundle pdf-bundle

Bundle for creating pdf documents out of twig templates

image

massive/pdf-bundle

Bundle for creating pdf documents out of twig templates

  • Thursday, March 23, 2017
  • by chirimoya
  • Repository
  • 24 Watchers
  • 0 Stars
  • 6,127 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 16 % Grown

The README.md

MassivePdfBundle

Built upon KnpSnappyBundle: https://github.com/KnpLabs/KnpSnappyBundle, (*1)

Installation

Install the bundle with composer., (*2)

``` json composer require massive/pdf-bundle, (*3)


**Add bundle to your symfony kernel.** ``` php new Knp\Bundle\SnappyBundle\KnpSnappyBundle(), new Massive\Bundle\PdfBundle\MassivePdfBundle(),

Install wkhtmltopdf

Ubuntu, (*4)

apt-get install wkhtmltopdf
apt-get install xvfb
echo ‘xvfb-run –server-args=”-screen 0, 1024x768x24″ /usr/bin/wkhtmltopdf $*’ > /usr/bin/wkhtmltopdf.sh
chmod a+x /usr/bin/wkhtmltopdf.sh
ln -s /usr/bin/wkhtmltopdf.sh /usr/local/bin/wkhtmltopdf
wkhtmltopdf http://www.google.com output.pdf

MacOSX, (*5)

http://wkhtmltopdf.org/downloads.html, (*6)

Configure Knp Snappy Bundle**

See KnpSnappyBundle for configuration., (*7)

Usage

Controller Trait, (*8)

The controller trait is the easiest way to generate a pdf:, (*9)

<?php

namespace AppBundle\Controller;

use Massive\Bundle\PdfBundle\Controller\RenderPdfTrait;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class YourController extends Controller
{
    use RenderPdfTrait;

    public function pdfAction(Request $request): Response
    {
        return $this->renderPdf(
            '@pdfs/your.html.twig',
            [
                'parameter' => 'hello'
            ],
            $request->getRequestFormat()
        );
    }
}

Register the route with default _format as pdf:, (*10)

    <route id="your.pdf" path="/your.{_format}">
        <default key="_controller">AppBundle:Your:pdf</default>
        <default key="_format">pdf</default>
    </route>

Now you can access the pdf with /your or use /your.html to get a html response (good for development)., (*11)

Generate Pdf, (*12)

/** @var \Massive\Bundle\PdfBundle\Pdf\PdfFactory $pdfFactory */
$pdfFactory = $this->get('massive_pdf.pdf_factory'); // get the service or inject it in your services configuration
$pdf = $pdfFactory->create('pdf.html.twig');

Embedding local assets, (*13)

The local_asset avoids doing a http request by using file:// instead of https:// for performance improvement:, (*14)

<img src="{{ local_asset('/images/image.jpg') }}" alt="Local Asset">

This will only work when $request->getRequestFormat() will return pdf and not html., (*15)

If you want to force using file:// set the second parameter to true:, (*16)

<img src="{{ local_asset('/images/image.jpg', true) }}" alt="Local Asset">

The Versions

23/03 2017

dev-develop

dev-develop

Bundle for creating pdf documents out of twig templates

  Sources   Download

MIT

The Requires

 

The Development Requires

by Philip Nachbauer
by Elias Hiller

pdf massive

23/03 2017

dev-feature/composer-description

dev-feature/composer-description

Bundle for creating pdf documents out of twig templates

  Sources   Download

MIT

The Requires

 

The Development Requires

by Philip Nachbauer
by Elias Hiller

pdf massive

14/10 2015

dev-master

9999999-dev

The Massive Bundle for managing pdf documents

  Sources   Download

MIT

The Requires

 

The Development Requires

pdf massive

14/10 2015

0.1.0

0.1.0.0

The Massive Bundle for managing pdf documents

  Sources   Download

MIT

The Requires

 

The Development Requires

pdf massive

24/09 2015

0.0.1

0.0.1.0

The Massive Bundle for managing pdf documents

  Sources   Download

MIT

The Requires

 

The Development Requires

pdf massive