1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Mpdf Renderer file |
4
|
|
|
* |
5
|
|
|
* @author Leandro Silva <[email protected]> |
6
|
|
|
* @category LosPdf |
7
|
|
|
* @license https://github.com/Lansoweb/LosPdf/blob/master/LICENSE BSD-3 License |
8
|
|
|
* @link http://github.com/LansoWeb/LosPdf |
9
|
|
|
*/ |
10
|
|
|
namespace LosPdf\View\Renderer; |
11
|
|
|
|
12
|
|
|
use mPDF; |
13
|
|
|
use LosPdf\View\Model\PdfModel; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Mpdf Renderer class |
17
|
|
|
* |
18
|
|
|
* @author Leandro Silva <[email protected]> |
19
|
|
|
* @category LosPdf |
20
|
|
|
* @license https://github.com/Lansoweb/LosPdf/blob/master/LICENSE BSD-3 License |
21
|
|
|
* @link http://github.com/LansoWeb/LosPdf |
22
|
|
|
*/ |
23
|
|
|
final class MpdfRenderer extends AbstractRenderer |
24
|
|
|
{ |
25
|
|
|
public function getEngine() |
26
|
|
|
{ |
27
|
|
|
if ($this->engine === null) { |
28
|
|
|
$this->engine = new mPDF(); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
return $this->engine; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
protected function doRender() |
35
|
|
|
{ |
36
|
|
|
return $this->getEngine()->Output(); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
protected function doPrepare($model, $values) |
40
|
|
|
{ |
41
|
|
|
$this->html = $this->renderer->render($model, $values); |
42
|
|
|
|
43
|
|
|
$paperOrientation = $this->getOption(PdfModel::PAPER_ORIENTATION, PdfModel::ORIENTATION_PORTRAIT); |
44
|
|
|
$paperSize = $this->getOption(PdfModel::PAPER_SIZE, PdfModel::SIZE_A4); |
45
|
|
|
|
46
|
|
|
if (!is_array($paperSize)) { |
47
|
|
|
$format = strtolower($paperOrientation[0]); |
48
|
|
|
if ($format == 'l') { |
49
|
|
|
$paperSize = $paperSize.'-'.$format; |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
$this->getEngine()->_setPageSize($paperSize, $paperOrientation); |
54
|
|
|
$this->getEngine()->WriteHTML($this->html); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
protected function doRenderToString(PdfModel $model) |
58
|
|
|
{ |
59
|
|
|
return $this->getEngine()->Output('', 'S'); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
protected function doRenderToFile(PdfModel $model, $fileName) |
63
|
|
|
{ |
64
|
|
|
return $this->getEngine()->Output($fileName, 'F'); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|