2017 © Pedro Peláez
 

zf3-module mvlabs-snappy

MvlabsSnappy is a Zend Framework module that allow easy to thumbnail, snapshot or PDF generation from a url or a html page using Snappy PHP wrapper for the wkhtmltopdf/wkhtmltoimage conversion utility.

image

mvlabs/mvlabs-snappy

MvlabsSnappy is a Zend Framework module that allow easy to thumbnail, snapshot or PDF generation from a url or a html page using Snappy PHP wrapper for the wkhtmltopdf/wkhtmltoimage conversion utility.

  • Friday, June 1, 2018
  • by drigani
  • Repository
  • 13 Watchers
  • 20 Stars
  • 33,535 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 12 Forks
  • 0 Open issues
  • 6 Versions
  • 3 % Grown

The README.md

MvlabsSnappy

Build Status Latest Stable Version Total Downloads License, (*1)

MvlabsSnappy is a Laminas 3 module that allow easy to thumbnail, snapshot or PDF generation from a url or a html page using Snappy PHP (5.6+) wrapper for the wkhtmltopdf conversion utility., (*2)

Installation

With composer

php composer.phar require mvlabs/mvlabs-snappy

Post installation

  1. Enabling it in your application.config.phpfile., (*3)

    <?php
    return [
        'modules' => [
            // ...
            'MvlabsSnappy',
        ],
        // ...
    ];
    

Configuration

After installing MvlabsSnappy, copy ./vendor/mvlabs/MvlabsSnappy/config/mvlabs-snappy.local.php.dist to ./config/autoload/mvlabs-snappy.local.php and change the binaries path and add options as desired., (*4)

# /config/autoload/mvlabs-snappy.local.php
<?php
return [
    'mvlabs-snappy' => [
        'pdf' => [
           'binary'  => '/usr/local/bin/wkhtmltopdf',
           'options' => [], // Type wkhtmltopdf -H to see the list of options
        ],
        'image' => [
            'binary'  => '/usr/local/bin/wkhtmltoimage',
            'options' => [], // Type wkhtmltoimage -H to see the list of options
         ]
     ]
];

wkhtmltopdf binary as composer dependencies

If you want to download wkhtmltopdf with composer you add to composer.json:, (*5)

{
    "require": {
        "h4cc/wkhtmltopdf-i386": "0.12.4"
    }
}

Or require the package for i386 with:, (*6)

php composer.phar require h4cc/wkhtmltopdf-i386 "0.12.4"

If you are in 64 bit based system:, (*7)

{
    "require": {
        "h4cc/wkhtmltopdf-amd64": "0.12.4"
    }
}

Or require the package for amd64 with:, (*8)

php composer.phar require h4cc/wkhtmltopdf-amd64 "0.12.4"

The binary will then be located at:, (*9)

vendor/h4cc/wkhtmltopdf-i386/bin/wkhtmltopdf-i386

Also a symlink will be created in your configured bin/ folder, for example:, (*10)

vendor/bin/wkhtmltopdf-i386

Usage

The module registers two services:, (*11)

  • the mvlabssnappy.image.service service allows you to generate images;
  • the mvlabssnappy.pdf.service service allows you to generate pdf files.

Generate an image from an URL

 $mvlabsSnappyImage = $container->get('mvlabssnappy.image.service'),
 $mvlabsSnappyImage->generate('http://www.mvlabs.it', '/path/to/myapp/data/image.jpg');

Generate a pdf document from an URL

 $mvlabsSnappyPdf = $container->get('mvlabssnappy.pdf.service'),
 $mvlabsSnappyPdf->generate('http://www.mvlabs.it', '/path/to/myapp/data/document.pdf');

Render a pdf document as response from a controller


class IndexController extends AbstractActionController { /** * @var Knp\Snappy\Pdf; */ protected $mvlabsSnappyPdf; /** * @var Laminas\View\Renderer\RendererInterface */ protected $renderer; public function __construct(Pdf $mvlabsSnappyPdf, RendererInterface $renderer) { $this->mvlabsSnappyPdf = $mvlabsSnappyPdf; $this->renderer = $renderer; } public function testPdfAction() { $now = new \DateTime(); $layoutViewModel = $this->layout(); $layoutViewModel->setTemplate('layout/pdf-layout'); $viewModel = new ViewModel([ 'vars' => $vars, ]); $viewModel->setTemplate('myModule/myController/pdf-template'); $layoutViewModel->setVariables([ 'content' => $this->renderer->render($viewModel), ]); $htmlOutput = $this->renderer->render($layoutViewModel); $output = $this->mvlabsSnappyPdf->getOutputFromHtml($htmlOutput); $response = $this->getResponse(); $headers = $response->getHeaders(); $headers->addHeaderLine('Content-Type', 'application/pdf'); $headers->addHeaderLine('Content-Disposition', "attachment; filename=\"export-" . $now->format('d-m-Y H:i:s') . ".pdf\""); $response->setContent($output); return $response; } }

Credits

MvlabsSnappy and Snappy are based on the awesome wkhtmltopdf. MvlabsSnappy has been developed by mvlabs., (*12)

The Versions

01/06 2018

dev-master

9999999-dev https://github.com/mvlabs/MvlabsSnappy.git

MvlabsSnappy is a Zend Framework module that allow easy to thumbnail, snapshot or PDF generation from a url or a html page using Snappy PHP wrapper for the wkhtmltopdf/wkhtmltoimage conversion utility.

  Sources   Download

MIT

The Requires

 

The Development Requires

zf2 pdf zf3 thumbnail wkhtmltopdf snappy wkhtmltoimage snapshot mvaassociati mvlabs

01/06 2018

1.0.1

1.0.1.0 https://github.com/mvlabs/MvlabsSnappy.git

MvlabsSnappy is a Zend Framework module that allow easy to thumbnail, snapshot or PDF generation from a url or a html page using Snappy PHP wrapper for the wkhtmltopdf/wkhtmltoimage conversion utility.

  Sources   Download

MIT

The Requires

 

The Development Requires

zf2 pdf zf3 thumbnail wkhtmltopdf snappy wkhtmltoimage snapshot mvlabs

30/05 2018

1.0.0

1.0.0.0 https://github.com/mvlabs/MvlabsSnappy.git

MvlabsSnappy is a Zend Framework module that allow easy to thumbnail, snapshot or PDF generation from a url or a html page using Snappy PHP wrapper for the wkhtmltopdf/wkhtmltoimage conversion utility.

  Sources   Download

MIT

The Requires

 

zf2 pdf zf3 thumbnail wkhtmltopdf snappy wkhtmltoimage snapshot mvlabs

04/08 2016

dev-feature/update-zf3

dev-feature/update-zf3 https://github.com/mvlabs/MvlabsSnappy.git

MvlabsSnappy is a ZF2 module that allow easy to thumbnail, snapshot or PDF generation from a url or a html page using Snappy PHP (5.3+) wrapper for the wkhtmltopdf/wkhtmltoimage conversion utility.

  Sources   Download

MIT

The Requires

 

zf2 pdf thumbnail wkhtmltopdf snappy wkhtmltoimage snapshot mvaassociati mvlabs

30/03 2015

0.2.0

0.2.0.0 https://github.com/mvlabs/MvlabsSnappy.git

MvlabsSnappy is a ZF2 module that allow easy to thumbnail, snapshot or PDF generation from a url or a html page using Snappy PHP (5.3+) wrapper for the wkhtmltopdf/wkhtmltoimage conversion utility.

  Sources   Download

MIT

The Requires

 

zf2 pdf thumbnail wkhtmltopdf snappy wkhtmltoimage snapshot mvaassociati mvlabs

05/08 2013

0.1.0

0.1.0.0 https://github.com/mvlabs/MvlabsSnappy.git

MvlabsSnappy is a ZF2 module that allow easy to thumbnail, snapshot or PDF generation from a url or a html page using Snappy PHP (5.3+) wrapper for the wkhtmltopdf/wkhtmltoimage conversion utility.

  Sources   Download

MIT

The Requires

 

zf2 pdf thumbnail wkhtmltopdf snappy wkhtmltoimage snapshot mvaassociati mvlabs