This repository was 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
/
Copy pathDompdf.php
55 lines (47 loc) · 1.42 KB
/
Dompdf.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
<?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\helpers\ArrayHelper;
use yii2tech\html2pdf\BaseConverter;
/**
* Dompdf converts file using [dompdf](https://github.com/dompdf/dompdf) library.
*
* This converter requires `dompdf` library to be installed. This can be done via composer:
*
* ```
* composer require --prefer-dist dompdf/dompdf:0.7.x@beta
* ```
*
* @see http://wkhtmltopdf.org/
*
* @author Paul Klimov <[email protected]>
* @since 1.0
*/
class Dompdf extends BaseConverter
{
/**
* {@inheritdoc}
*/
protected function convertInternal($html, $outputFileName, $options)
{
$pageSize = ArrayHelper::remove($options, 'pageSize', 'A4');
$orientation = ArrayHelper::remove($options, 'orientation', 'portrait');
if (empty($options)) {
$dompdfOptions = null;
} else {
$dompdfOptions = new \Dompdf\Options();
foreach ($options as $name => $value) {
$dompdfOptions->set($name, $value);
}
}
$dompdf = new \Dompdf\Dompdf($dompdfOptions);
$dompdf->setPaper($pageSize, $orientation);
$dompdf->loadHtml($html);
$dompdf->render();
file_put_contents($outputFileName, $dompdf->output());
}
}