|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Factories; |
|
4
|
|
|
|
|
5
|
|
|
use Mpdf\Mpdf; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* PdfFactory |
|
9
|
|
|
* |
|
10
|
|
|
* factory to create instance of Mpdf |
|
11
|
|
|
* |
|
12
|
|
|
* @created 2016-07-07 |
|
13
|
|
|
* @author Tomas Litera <[email protected]> |
|
14
|
|
|
*/ |
|
15
|
|
|
class PdfFactory |
|
16
|
|
|
{ |
|
17
|
|
|
/** @var Pdf */ |
|
18
|
|
|
public $pdf; |
|
19
|
|
|
|
|
20
|
|
|
/** @var defaults */ |
|
21
|
|
|
private $encoding = 'utf-8'; |
|
22
|
|
|
private $paperFormat = 'A4'; |
|
23
|
|
|
private $fontSize = 0; |
|
24
|
|
|
private $font = ''; |
|
25
|
|
|
private $marginLeft = 15; |
|
26
|
|
|
private $marginRight = 15; |
|
27
|
|
|
private $marginTop = 16; |
|
28
|
|
|
private $marginBottom = 16; |
|
29
|
|
|
private $debugMode = false; |
|
30
|
|
|
|
|
31
|
|
|
/** Constructor */ |
|
32
|
|
|
public function __construct(array $configuration) |
|
33
|
|
|
{ |
|
34
|
|
|
$this->encoding = $configuration['encoding']; |
|
35
|
|
|
$this->paperFormat = $configuration['paperFormat']; |
|
36
|
|
|
$this->fontSize = $configuration['fontSize']; |
|
37
|
|
|
$this->font = $configuration['font']; |
|
38
|
|
|
$this->marginLeft = $configuration['marginLeft']; |
|
39
|
|
|
$this->marginRight = $configuration['marginRight']; |
|
40
|
|
|
$this->marginTop = $configuration['marginTop']; |
|
41
|
|
|
$this->marginBottom = $configuration['marginBottom']; |
|
42
|
|
|
$this->debugMode = $configuration['debugMode']; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Return new Mpdf with few settings |
|
47
|
|
|
* |
|
48
|
|
|
* @return Mpdf; |
|
|
|
|
|
|
49
|
|
|
*/ |
|
50
|
|
|
public function create() |
|
51
|
|
|
{ |
|
52
|
|
|
$this->pdf = new Mpdf([ |
|
|
|
|
|
|
53
|
|
|
$this->encoding, |
|
54
|
|
|
$this->paperFormat, |
|
55
|
|
|
$this->fontSize, |
|
56
|
|
|
$this->font, |
|
57
|
|
|
$this->marginLeft, |
|
58
|
|
|
$this->marginRight, |
|
59
|
|
|
$this->marginTop, |
|
60
|
|
|
$this->marginBottom |
|
61
|
|
|
] |
|
62
|
|
|
); |
|
63
|
|
|
|
|
64
|
|
|
// debugging on demand |
|
65
|
|
|
if($this->debugMode){ |
|
66
|
|
|
$this->pdf->debug = true; |
|
67
|
|
|
} |
|
68
|
|
|
$this->pdf->useOnlyCoreFonts = true; |
|
69
|
|
|
$this->pdf->SetDisplayMode('fullpage'); |
|
70
|
|
|
$this->pdf->autoScriptToLang = false; |
|
71
|
|
|
$this->pdf->defaultfooterfontsize = 16; |
|
72
|
|
|
$this->pdf->defaultfooterfontstyle = 'B'; |
|
73
|
|
|
|
|
74
|
|
|
return $this->pdf; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Set margins of PDF |
|
79
|
|
|
*/ |
|
80
|
|
|
public function setMargins($left, $right, $top, $bottom) |
|
81
|
|
|
{ |
|
82
|
|
|
$this->marginLeft = $left; |
|
83
|
|
|
$this->marginRight = $right; |
|
84
|
|
|
$this->marginTop = $top; |
|
85
|
|
|
$this->marginBottom = $bottom; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Set paper format of PDF |
|
90
|
|
|
*/ |
|
91
|
|
|
public function setPaperFormat($paperFormat) |
|
92
|
|
|
{ |
|
93
|
|
|
$this->paperFormat = $paperFormat; |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.