composer package updates
[openemr.git] / vendor / knplabs / knp-snappy / src / Knp / Snappy / Pdf.php
blobac53ff3c6b57b15b646eae0bac2bacc9198afc68
1 <?php
3 namespace Knp\Snappy;
5 /**
6 * Use this class to transform a html/a url to a pdf.
9 * @author Matthieu Bontemps <matthieu.bontemps@knplabs.com>
10 * @author Antoine Hérault <antoine.herault@knplabs.com>
12 class Pdf extends AbstractGenerator
14 protected $optionsWithContentCheck = [];
16 /**
17 * {@inheritdoc}
19 public function __construct($binary = null, array $options = [], array $env = null)
21 $this->setDefaultExtension('pdf');
22 $this->setOptionsWithContentCheck();
24 parent::__construct($binary, $options, $env);
27 /**
28 * Handle options to transform HTML strings into temporary files containing HTML.
30 * @param array $options
32 * @return array $options Transformed options
34 protected function handleOptions(array $options = [])
36 foreach ($options as $option => $value) {
37 if (null === $value) {
38 unset($options[$option]);
39 continue;
42 if (!empty($value) && array_key_exists($option, $this->optionsWithContentCheck)) {
43 $saveToTempFile = !$this->isFile($value) && !$this->isOptionUrl($value);
44 $fetchUrlContent = $option === 'xsl-style-sheet' && $this->isOptionUrl($value);
46 if ($saveToTempFile || $fetchUrlContent) {
47 $fileContent = $fetchUrlContent ? file_get_contents($value) : $value;
48 $options[$option] = $this->createTemporaryFile($fileContent, $this->optionsWithContentCheck[$option]);
53 return $options;
56 /**
57 * {@inheritdoc}
59 public function generate($input, $output, array $options = [], $overwrite = false)
61 $options = $this->handleOptions($this->mergeOptions($options));
63 parent::generate($input, $output, $options, $overwrite);
66 /**
67 * Convert option content or url to file if it is needed.
69 * @param $option
71 * @return bool
73 protected function isOptionUrl($option)
75 return (bool) filter_var($option, FILTER_VALIDATE_URL);
78 /**
79 * {@inheritdoc}
81 protected function configure()
83 $this->addOptions([
84 'ignore-load-errors' => null, // old v0.9
85 'lowquality' => true,
86 'collate' => null,
87 'no-collate' => null,
88 'cookie-jar' => null,
89 'copies' => null,
90 'dpi' => null,
91 'extended-help' => null,
92 'grayscale' => null,
93 'help' => null,
94 'htmldoc' => null,
95 'image-dpi' => null,
96 'image-quality' => null,
97 'manpage' => null,
98 'margin-bottom' => null,
99 'margin-left' => null,
100 'margin-right' => null,
101 'margin-top' => null,
102 'orientation' => null,
103 'output-format' => null,
104 'page-height' => null,
105 'page-size' => null,
106 'page-width' => null,
107 'no-pdf-compression' => null,
108 'quiet' => null,
109 'read-args-from-stdin' => null,
110 'title' => null,
111 'use-xserver' => null,
112 'version' => null,
113 'dump-default-toc-xsl' => null,
114 'dump-outline' => null,
115 'outline' => null,
116 'no-outline' => null,
117 'outline-depth' => null,
118 'allow' => null,
119 'background' => null,
120 'no-background' => null,
121 'checkbox-checked-svg' => null,
122 'checkbox-svg' => null,
123 'cookie' => null,
124 'custom-header' => null,
125 'custom-header-propagation' => null,
126 'no-custom-header-propagation' => null,
127 'debug-javascript' => null,
128 'no-debug-javascript' => null,
129 'default-header' => null,
130 'encoding' => null,
131 'disable-external-links' => null,
132 'enable-external-links' => null,
133 'disable-forms' => null,
134 'enable-forms' => null,
135 'images' => null,
136 'no-images' => null,
137 'disable-internal-links' => null,
138 'enable-internal-links' => null,
139 'disable-javascript' => null,
140 'enable-javascript' => null,
141 'javascript-delay' => null,
142 'load-error-handling' => null,
143 'load-media-error-handling' => null,
144 'disable-local-file-access' => null,
145 'enable-local-file-access' => null,
146 'minimum-font-size' => null,
147 'exclude-from-outline' => null,
148 'include-in-outline' => null,
149 'page-offset' => null,
150 'password' => null,
151 'disable-plugins' => null,
152 'enable-plugins' => null,
153 'post' => null,
154 'post-file' => null,
155 'print-media-type' => null,
156 'no-print-media-type' => null,
157 'proxy' => null,
158 'radiobutton-checked-svg' => null,
159 'radiobutton-svg' => null,
160 'run-script' => null,
161 'disable-smart-shrinking' => null,
162 'enable-smart-shrinking' => null,
163 'stop-slow-scripts' => null,
164 'no-stop-slow-scripts' => null,
165 'disable-toc-back-links' => null,
166 'enable-toc-back-links' => null,
167 'user-style-sheet' => null,
168 'username' => null,
169 'window-status' => null,
170 'zoom' => null,
171 'footer-center' => null,
172 'footer-font-name' => null,
173 'footer-font-size' => null,
174 'footer-html' => null,
175 'footer-left' => null,
176 'footer-line' => null,
177 'no-footer-line' => null,
178 'footer-right' => null,
179 'footer-spacing' => null,
180 'header-center' => null,
181 'header-font-name' => null,
182 'header-font-size' => null,
183 'header-html' => null,
184 'header-left' => null,
185 'header-line' => null,
186 'no-header-line' => null,
187 'header-right' => null,
188 'header-spacing' => null,
189 'replace' => null,
190 'disable-dotted-lines' => null,
191 'cover' => null,
192 'toc' => null,
193 'toc-depth' => null,
194 'toc-font-name' => null,
195 'toc-l1-font-size' => null,
196 'toc-header-text' => null,
197 'toc-header-font-name' => null,
198 'toc-header-font-size' => null,
199 'toc-level-indentation' => null,
200 'disable-toc-links' => null,
201 'toc-text-size-shrink' => null,
202 'xsl-style-sheet' => null,
203 'viewport-size' => null,
204 'redirect-delay' => null, // old v0.9
205 'cache-dir' => null,
206 'keep-relative-links' => null,
207 'resolve-relative-links' => null,
212 * Array with options which require to store the content of the option before passing it to wkhtmltopdf.
214 protected function setOptionsWithContentCheck()
216 $this->optionsWithContentCheck = [
217 'header-html' => 'html',
218 'footer-html' => 'html',
219 'cover' => 'html',
220 'xsl-style-sheet'=> 'xsl',