|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Sfneal\ViewExport\Pdf\Utils; |
|
4
|
|
|
|
|
5
|
|
|
use Dompdf\Options; |
|
6
|
|
|
|
|
7
|
|
|
class DefaultOptions extends Options |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* Set the content loader convention. |
|
11
|
|
|
* |
|
12
|
|
|
* - If this setting is set to 'disk' PDF content will be exported to a static HTML. |
|
13
|
|
|
* - If this setting is set to 'memory' PDF content will be loaded directly to the PDF. |
|
14
|
|
|
* |
|
15
|
|
|
* @var string |
|
16
|
|
|
*/ |
|
17
|
|
|
private $contentLoader; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* DefaultOptions constructor. |
|
21
|
|
|
* |
|
22
|
|
|
* @param array|null $attributes |
|
23
|
|
|
*/ |
|
24
|
|
|
public function __construct(array $attributes = null) |
|
25
|
|
|
{ |
|
26
|
|
|
parent::__construct($attributes); |
|
27
|
|
|
|
|
28
|
|
|
$this->setDefaults(); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Set the default Dompdf Options. |
|
33
|
|
|
* |
|
34
|
|
|
* @return void |
|
35
|
|
|
*/ |
|
36
|
|
|
private function setDefaults(): void |
|
37
|
|
|
{ |
|
38
|
|
|
// Set file permissions |
|
39
|
|
|
$this->setChroot(config('view-export.pdf.chroot')); |
|
40
|
|
|
|
|
41
|
|
|
// Set font cache directory (if overwritten in config) |
|
42
|
|
|
if (config('view-export.pdf.font_cache')) { |
|
43
|
|
|
$this->setFontCache(config('view-export.pdf.font_cache')); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
// Set parsing options |
|
47
|
|
|
$this->setIsPhpEnabled(config('view-export.pdf.php_enabled')); |
|
48
|
|
|
$this->setIsJavascriptEnabled(config('view-export.pdf.javascript_enabled')); |
|
49
|
|
|
$this->setIsHtml5ParserEnabled(config('view-export.pdf.html5_parsable')); |
|
50
|
|
|
$this->setIsRemoteEnabled(config('view-export.pdf.remote_enabled')); |
|
51
|
|
|
|
|
52
|
|
|
// Set logging directory |
|
53
|
|
|
$this->setLogOutputFile(config('view-export.pdf.log_output')); |
|
54
|
|
|
|
|
55
|
|
|
// Set content loader |
|
56
|
|
|
$this->setContentLoader(config('view-export.pdf.content_loader', 'disk')); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Set the paper orientation to 'landscape'. |
|
61
|
|
|
* |
|
62
|
|
|
* @return $this |
|
63
|
|
|
*/ |
|
64
|
|
|
public function setLandscape(): self |
|
65
|
|
|
{ |
|
66
|
|
|
$this->setDefaultPaperOrientation('landscape'); |
|
67
|
|
|
|
|
68
|
|
|
return $this; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Set the paper orientation to 'portrait'. |
|
73
|
|
|
* |
|
74
|
|
|
* @return $this |
|
75
|
|
|
*/ |
|
76
|
|
|
public function setPortrait(): self |
|
77
|
|
|
{ |
|
78
|
|
|
$this->setDefaultPaperOrientation('portrait'); |
|
79
|
|
|
|
|
80
|
|
|
return $this; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Set the content loader type as 'disk'. |
|
85
|
|
|
* |
|
86
|
|
|
* @return $this |
|
87
|
|
|
*/ |
|
88
|
|
|
public function setContentLoaderDisk(): self |
|
89
|
|
|
{ |
|
90
|
|
|
return $this->setContentLoader('disk'); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Set the content loader type as 'memory'. |
|
95
|
|
|
* |
|
96
|
|
|
* @return $this |
|
97
|
|
|
*/ |
|
98
|
|
|
public function setContentLoaderMemory(): self |
|
99
|
|
|
{ |
|
100
|
|
|
return $this->setContentLoader('memory'); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Set the content loader type. |
|
105
|
|
|
* |
|
106
|
|
|
* @param string $loader |
|
107
|
|
|
* @return $this |
|
108
|
|
|
*/ |
|
109
|
|
|
private function setContentLoader(string $loader): self |
|
110
|
|
|
{ |
|
111
|
|
|
$this->contentLoader = $loader; |
|
112
|
|
|
|
|
113
|
|
|
return $this; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* Determine if the content loader type is 'disk'. |
|
118
|
|
|
* |
|
119
|
|
|
* @return bool |
|
120
|
|
|
*/ |
|
121
|
|
|
public function isContentLoaderDisk(): bool |
|
122
|
|
|
{ |
|
123
|
|
|
return $this->getContentLoader() == 'disk'; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* Determine if the content loader type is 'memory'. |
|
128
|
|
|
* |
|
129
|
|
|
* @return bool |
|
130
|
|
|
*/ |
|
131
|
|
|
public function isContentLoaderMemory(): bool |
|
132
|
|
|
{ |
|
133
|
|
|
return $this->getContentLoader() == 'memory'; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* Retrieve the content loader type. |
|
138
|
|
|
* |
|
139
|
|
|
* @return string |
|
140
|
|
|
*/ |
|
141
|
|
|
public function getContentLoader(): string |
|
142
|
|
|
{ |
|
143
|
|
|
return $this->contentLoader; |
|
144
|
|
|
} |
|
145
|
|
|
} |
|
146
|
|
|
|