This repository has been archived by the owner on Jan 10, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 65
/
Tcpdf.php
58 lines (50 loc) · 1.56 KB
/
Tcpdf.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
/**
* @link https://github.com/yii2tech
* @copyright Copyright (c) 2015 Yii2tech
* @license [New BSD License](http://www.opensource.org/licenses/bsd-license.php)
*/
namespace yii2tech\html2pdf\converters;
use Yii;
use yii\helpers\ArrayHelper;
use yii2tech\html2pdf\BaseConverter;
/**
* Tcpdf converts file using [TCPDF](http://www.tcpdf.org) library.
*
* This converter requires `TCPDF` library to be installed. This can be done via composer:
*
* ```
* composer require --prefer-dist tecnickcom/tcpdf
* ```
*
* @author Paul Klimov <[email protected]>
* @since 1.0
*/
class Tcpdf extends BaseConverter
{
/**
* {@inheritdoc}
*/
protected function convertInternal($html, $outputFileName, $options)
{
$charset = ArrayHelper::remove($options, 'charset', Yii::$app->charset);
$pageSize = ArrayHelper::remove($options, 'pageSize', 'A4');
$orientation = ucfirst(ArrayHelper::remove($options, 'orientation', 'P'));
$unit = ArrayHelper::remove($options, 'unit', 'mm');
$pdf = new \TCPDF($orientation, $unit, $pageSize, true, $charset, false);
// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
foreach ($options as $name => $value) {
$setter = 'Set' . $name;
if (method_exists($pdf, $setter)) {
$pdf->$setter($value);
} else {
$pdf->$name = $value;
}
}
// add a page
$pdf->AddPage();
$pdf->WriteHTML($html);
$pdf->Output($outputFileName, 'F');
}
}