2017 © Pedro Peláez
 

yii2-extension html2pdf

Provides support for HTML to PDF and PHP to PDF conversion

image

yii2tech/html2pdf

Provides support for HTML to PDF and PHP to PDF conversion

  • Tuesday, May 22, 2018
  • by klimov-paul
  • Repository
  • 7 Watchers
  • 52 Stars
  • 24,414 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 15 Forks
  • 0 Open issues
  • 5 Versions
  • 20 % Grown

The README.md

, (*1)

HTML to PDF conversion extension for Yii2


This extension provides basic support for HTML to PDF and PHP to PDF conversion., (*2)

For license information check the LICENSE-file., (*3)

Latest Stable Version Total Downloads Build Status, (*4)

Installation

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

Either run, (*6)

php composer.phar require --prefer-dist yii2tech/html2pdf

or add, (*7)

"yii2tech/html2pdf": "*"

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

Note: you'll have to install software for the actual HTML to PDF conversion separately, depending on the particular converter, you would like to use., (*9)

Usage

This extension provides support for HTML to PDF and PHP to PDF conversion. It allows composition of the PDF files from HTML and via rendering PHP templates., (*10)

Extension functionality is aggregated into \yii2tech\html2pdf\Manager application component. Application configuration example:, (*11)

 [
        'html2pdf' => [
            'class' => 'yii2tech\html2pdf\Manager',
            'viewPath' => '@app/views/pdf',
            'converter' => 'wkhtmltopdf',
        ],
    ],
    ...
];
```

For the simple conversion you can use `\yii2tech\html2pdf\Manager::convert()` and `\yii2tech\html2pdf\Manager::convertFile()` methods:

```php




Simple Content, (*12)

HTML; // create PDF file from HTML content : Yii::$app->html2pdf ->convert($html) ->saveAs('/path/to/output.pdf'); // convert HTML file to PDF file : Yii::$app->html2pdf ->convertFile('/path/to/source.html') ->saveAs('/path/to/output.pdf'); ``` The actual conversion result determined by particular converter used. You may use `\yii2tech\html2pdf\Manager::$converter` property for the converter setup. Several built-in converters are provided: - [yii2tech\html2pdf\converters\Wkhtmltopdf](src/converters/Wkhtmltopdf.php) - uses [wkhtmltopdf](http://wkhtmltopdf.org/) utility for the conversion. - [yii2tech\html2pdf\converters\Dompdf](src/converters/Dompdf.php) - uses [dompdf](https://github.com/dompdf/dompdf) library for the conversion. - [yii2tech\html2pdf\converters\Mpdf](src/converters/Mpdf.php) - uses [mpdf](https://github.com/mpdf/mpdf) library for the conversion. - [yii2tech\html2pdf\converters\Tcpdf](src/converters/Tcpdf.php) - uses [TCPDF](http://www.tcpdf.org) library for the conversion. - [yii2tech\html2pdf\converters\Callback](src/converters/Callback.php) - uses a custom PHP callback for the conversion. **Heads up!** Most of the provided converters require additional software been installed, which is not provided by his extension by default. You'll have to install it manually, once you decide, which converter you will use. Please refer to the particular converter class for more details. You may specify conversion options via second argument of the `convert()` or `convertFile()` method: ```php html2pdf ->convertFile('/path/to/source.html', ['pageSize' => 'A4']) ->saveAs('/path/to/output.pdf'); ``` You may setup default conversion options at the `\yii2tech\html2pdf\Manager` level: ```php [ 'html2pdf' => [ 'class' => 'yii2tech\html2pdf\Manager', 'viewPath' => '@app/pdf', 'converter' => [ 'class' => 'yii2tech\html2pdf\converters\Wkhtmltopdf', 'defaultOptions' => [ 'pageSize' => 'A4' ], ] ], ], ... ]; ``` > Note: the actual list of available conversion options depends on the particular converter to be used. ## Template usage You may create PDF files rendering PHP templates (view files), which composes HTML output. Such files are processed as regular view files, allowing passing params and layout wrapping. Method `\yii2tech\html2pdf\Manager::render()` used for this: ```php html2pdf ->render('invoice', ['user' => Yii::$app->user->identity]) ->saveAs('/path/to/output.pdf'); ``` You may use a shared layout for the templates, which can be setup via `\yii2tech\html2pdf\Manager::$layout`. During each rendering view is working in context of `\yii2tech\html2pdf\Template` object, which can be used to adjust layout or PDF conversion options inside view file: ```php context; $context->layout = 'layouts/payment'; // use specific layout for this template // specify particular PDF conversion for this template: $context->pdfOptions = [ 'pageSize' => 'A4', // ... ]; ?> , (*13)

Invoice

For: = $user->name ?>, (*14)

... , (*15)

The Versions

22/05 2018

dev-master

9999999-dev

Provides support for HTML to PDF and PHP to PDF conversion

  Sources   Download

BSD-3-Clause

The Requires

 

by Paul Klimov

template yii2 pdf conversion convert html2pdf php2pdf

09/04 2018

1.0.3

1.0.3.0

Provides support for HTML to PDF and PHP to PDF conversion

  Sources   Download

BSD-3-Clause

The Requires

 

by Paul Klimov

template yii2 pdf conversion convert html2pdf php2pdf

13/02 2018

1.0.2

1.0.2.0

Provides support for HTML to PDF and PHP to PDF conversion

  Sources   Download

BSD-3-Clause

The Requires

 

by Paul Klimov

template yii2 pdf conversion convert html2pdf php2pdf

03/11 2017

1.0.1

1.0.1.0

Provides support for HTML to PDF and PHP to PDF conversion

  Sources   Download

BSD-3-Clause

The Requires

 

by Paul Klimov

template yii2 pdf conversion convert html2pdf php2pdf

19/05 2016

1.0.0

1.0.0.0

Provides support for HTML to PDF and PHP to PDF conversion

  Sources   Download

BSD-3-Clause

The Requires

 

by Paul Klimov

template yii2 pdf conversion convert html2pdf php2pdf