2017 © Pedro Peláez
 

yii2-extension yii2-htmlconverter

Supports conversion of HTML to PDF or images

image

boundstate/yii2-htmlconverter

Supports conversion of HTML to PDF or images

  • Friday, May 15, 2015
  • by mikejpeters
  • Repository
  • 2 Watchers
  • 4 Stars
  • 2,262 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 2 Open issues
  • 2 Versions
  • 10 % Grown

The README.md

yii2-htmlconverter

Extension for the Yii2 framework that converts HTML to PDF or images using wkhtmltopdf., (*1)

Installation

This extensions relies on wkhtmltopdf. Installation insructions are provided on the wkhtmltopdf website., (*2)

The preferred way to install this extension is through composer., (*3)

Either run, (*4)

php composer.phar require --prefer-dist boundstate/yii2-htmlconverter "*"

or add, (*5)

"boundstate/yii2-htmlconverter": "*"

to the require section of your composer.json file., (*6)

Usage

Setup the components in your config:, (*7)

'htmlToPdf' => [
    'class' => 'boundstate\htmlconverter\HtmlToPdfConverter',
    'bin' => '/usr/bin/wkhtmltopdf',
    // global wkhtmltopdf command line options
    // (see http://wkhtmltopdf.org/usage/wkhtmltopdf.txt)
    'options' => [
        'print-media-type',
        'disable-smart-shrinking',
        'no-outline',
        'page-size' => 'letter',
        'load-error-handling' => 'ignore',
        'load-media-error-handling' => 'ignore'
    ],
],
'htmlToImage' => [
    'class' => 'boundstate\htmlconverter\HtmlToImageConverter',
    'bin' => '/usr/bin/wkhtmltoimage',
],
'response' => [
    'formatters' => [
        'pdf' => [
            'class' => 'boundstate\htmlconverter\PdfResponseFormatter',
            // Set a filename to download the response as an attachments (instead of displaying in browser)
            'filename' => 'attachment.pdf'
        ],
        'image' => [
            'class' => 'boundstate\htmlconverter\ImageResponseFormatter',
        ],
    ]
],

Now you can format a response as a PDF:, (*8)

Yii::$app->response->format = 'pdf';

Or format a response as an image:, (*9)

Yii::$app->response->format = 'image';

You can also manually generate a PDF from HTML:, (*10)

$html = $this->render('hello-word');
$header = $this->render('hello-world-header');
$pdf = Yii::$app->htmlToPdf->convert($html, ['page-size' => 'A4', 'header-html' => $header]);

Or manually generate an image from HTML:, (*11)

$html = $this->render('hello-word');
$pdf = Yii::$app->htmlToImage->convert($html);

The Versions

15/05 2015

dev-master

9999999-dev

Supports conversion of HTML to PDF or images

  Sources   Download

MIT

by Bound State Software

yii2 html image pdf wkhtmltopdf wkhtmltoimage wkhtmltox

15/05 2015

v0.0.1

0.0.1.0

Supports conversion of HTML to PDF or images

  Sources   Download

MIT

by Bound State Software

yii2 html image pdf wkhtmltopdf wkhtmltoimage wkhtmltox