1 | <?php include("head.inc"); ?> |
---|
2 | <a name="FAQ"> </a> |
---|
3 | <h2>Frequently Asked Questions</h2> |
---|
4 | |
---|
5 | <ol> |
---|
6 | <li><a href="#hello_world">Is there a 'hello world' script for dompdf?</a></li> |
---|
7 | |
---|
8 | <li><a href="#save">How do I save a PDF to disk?</a></li> |
---|
9 | |
---|
10 | <li><a href="#dom">I'm getting the following error: <br/> |
---|
11 | Fatal error: DOMPDF_autoload() [function.require]: Failed opening required |
---|
12 | '/var/www/dompdf/include/domdocument.cls.php' |
---|
13 | (include_path='.:') in |
---|
14 | /var/www/dompdf/dompdf_config.inc.php |
---|
15 | on line 146</a></li> |
---|
16 | |
---|
17 | <li><a href="#exec_time">I'm getting the following error: <br/> Fatal error: |
---|
18 | Maximum execution time of 30 seconds exceeded in /var/www/dompdf/dompdf.php |
---|
19 | on line XXX</a></li> |
---|
20 | |
---|
21 | <li><a href="#no_block_parent">I'm getting the following error:<br/> |
---|
22 | Fatal error: Uncaught exception 'DOMPDF_Exception' with message 'No |
---|
23 | block-level parent found. Not good.' in |
---|
24 | C:\Program Files\Apache\htdocs\dompdf\include\inline_positioner.cls.php:68 |
---|
25 | ... |
---|
26 | </a></li> |
---|
27 | |
---|
28 | <li><a href="#tables">I have a big table and it's broken!</a></li> |
---|
29 | |
---|
30 | <li><a href="#footers">Is there a way to add headers and footers?</a></li> |
---|
31 | |
---|
32 | <li><a href="#page_break">How do I insert page breaks?</a></li> |
---|
33 | |
---|
34 | <li><a href="#zend_optimizer">I'm getting the following error:<br/> |
---|
35 | Cannot access undefined property for object with |
---|
36 | overloaded property access in |
---|
37 | /var/www/dompdf/include/frame_tree.cls.php on line 160 |
---|
38 | </a></li> |
---|
39 | |
---|
40 | <li><a href="#new_window">How can I make PDFs open in the browser window instead of |
---|
41 | opening the download dialog?</a></li> |
---|
42 | |
---|
43 | <li><a href="#centre">How do I centre a table, paragraph or div?</li> |
---|
44 | </ol> |
---|
45 | |
---|
46 | <div class="divider1"> </div> |
---|
47 | <div class="answers"> |
---|
48 | <a name="hello_world"> </a> |
---|
49 | <h3>Is there a 'hello world' script for dompdf?</h3> |
---|
50 | |
---|
51 | <p>Here's a hello world script: |
---|
52 | <pre> |
---|
53 | <?php |
---|
54 | require_once("dompdf_config.inc.php"); |
---|
55 | $html = |
---|
56 | '<html><body>'. |
---|
57 | '<p>Hello World!</p>'. |
---|
58 | '</body></html>'; |
---|
59 | |
---|
60 | $dompdf = new DOMPDF(); |
---|
61 | $dompdf->load_html($html); |
---|
62 | |
---|
63 | $dompdf->render(); |
---|
64 | $dompdf->stream("hello_world.pdf"); |
---|
65 | |
---|
66 | ?> |
---|
67 | </pre> |
---|
68 | |
---|
69 | <p>Put this script in the same directory as |
---|
70 | dompdf_config.inc.php. You'll have to change the paths in |
---|
71 | dompdf_config.inc.php to match your installation.</p> |
---|
72 | |
---|
73 | <a href="#FAQ">[back to top]</a> |
---|
74 | <div class="divider2" style="background-position: 25% 0%"> </div> |
---|
75 | |
---|
76 | <a name="save"> </a> |
---|
77 | <h3>How do I save a PDF to disk?</h3> |
---|
78 | |
---|
79 | <p>If you are using the included <a href="usage.php#web">dompdf.php</a> script you |
---|
80 | can pass it the "save_file" option in conjunction with the "output_file" option.</p> |
---|
81 | |
---|
82 | <p>If you are using the DOMPDF class, you can save the generated PDF |
---|
83 | by calling <code>$dompdf->output()</code>:</p> |
---|
84 | |
---|
85 | <pre> |
---|
86 | require_once("dompdf_config.inc.php"); |
---|
87 | $html = |
---|
88 | '<html><body>'. |
---|
89 | '<p>Foo</p>'. |
---|
90 | '</body></html>'; |
---|
91 | |
---|
92 | $dompdf = new DOMPDF(); |
---|
93 | $dompdf->load_html($html); |
---|
94 | |
---|
95 | $dompdf->render(); |
---|
96 | |
---|
97 | // The next call will store the entire PDF as a string in $pdf |
---|
98 | |
---|
99 | $pdf = $dompdf->output(); |
---|
100 | |
---|
101 | // You can now write $pdf to disk, store it in a database or stream it |
---|
102 | // to the client. |
---|
103 | |
---|
104 | file_put_contents("saved_pdf.pdf", $pdf); |
---|
105 | </pre> |
---|
106 | |
---|
107 | <p>Note that typically <code>dompdf->stream()</code> and |
---|
108 | <code>dompdf->output()</code> are mutually exclusive.</p> |
---|
109 | |
---|
110 | <a href="#FAQ">[back to top]</a> |
---|
111 | <div class="divider1" style="background-position: 721px 0%"> </div> |
---|
112 | |
---|
113 | |
---|
114 | <a name="dom"> </a> |
---|
115 | <h3>I'm getting the following error: <br/> |
---|
116 | Fatal error: DOMPDF_autoload() [function.require]: Failed opening required |
---|
117 | '/var/www/dompdf/include/domdocument.cls.php' |
---|
118 | (include_path='.:') in |
---|
119 | /var/www/dompdf/dompdf_config.inc.php |
---|
120 | on line 146</h3> |
---|
121 | |
---|
122 | <p>This error occurs when the version of PHP that you are using does not have |
---|
123 | the DOM extension enabled. You can check which extensions are enabled by |
---|
124 | examning the output of <code>phpinfo()</code>.</p> |
---|
125 | |
---|
126 | <p>There are a couple of ways that the DOM extension could have been |
---|
127 | disabled. DOM uses libxml, so if libxml is not present on your server |
---|
128 | then the DOM extension will not work. Alternatively, if PHP was compiled |
---|
129 | with the '--disable-dom' switch or the '--disable-xml' switch, DOM support |
---|
130 | will also be removed. You can check which switches were used to compile |
---|
131 | PHP with <code>phpinfo()</code>.</p> |
---|
132 | |
---|
133 | <a href="#FAQ">[back to top]</a> |
---|
134 | <div class="divider1" style="background-position: 239px 0%"> </div> |
---|
135 | |
---|
136 | <a name="exec_time"> </a> |
---|
137 | <h3>I'm getting the following error: <br/> Fatal error: |
---|
138 | Maximum execution time of 30 seconds exceeded in /var/www/dompdf/dompdf.php |
---|
139 | on line XXX</h3> |
---|
140 | |
---|
141 | <p>Nested tables are not supported yet (v0.4.3) and can cause dompdf to enter an |
---|
142 | endless loop, thus giving rise to this error.</p> |
---|
143 | |
---|
144 | <a href="#FAQ">[back to top]</a> |
---|
145 | <div class="divider1" style="background-position: 300px 0%"> </div> |
---|
146 | |
---|
147 | <a name="no_block_parent"> </a> |
---|
148 | <h3>I'm getting the following error:<br/> |
---|
149 | Fatal error: Uncaught exception 'DOMPDF_Exception' with message 'No |
---|
150 | block-level parent found. Not good.' in |
---|
151 | C:\Program Files\Apache\htdocs\dompdf\include\inline_positioner.cls.php:68 |
---|
152 | ...</h3> |
---|
153 | |
---|
154 | <p>This should be fixed in versions 0.4.1 and up. The error was |
---|
155 | caused by <code>parse_url()</code> thinking that the 'c' in 'c:\' was |
---|
156 | a protocol. Version 0.4.1 works around this issue.</p> |
---|
157 | |
---|
158 | <a href="#FAQ">[back to top]</a> |
---|
159 | <div class="divider2" style="background-position: 130px 0%"> </div> |
---|
160 | |
---|
161 | <a name="tables"> </a> |
---|
162 | <h3>I have a big table and it's broken!</h3> |
---|
163 | |
---|
164 | <p>This is fixed in versions 0.4 and higher. Previous versions did not support tables that spanned pages.</p> |
---|
165 | |
---|
166 | <a href="#FAQ">[back to top]</a> |
---|
167 | <div class="divider1" style="background-position: 812px 0%"> </div> |
---|
168 | |
---|
169 | <a name="footers"> </a> |
---|
170 | <h3>Is there a way to add headers and footers?</h3> |
---|
171 | |
---|
172 | <p>Yes, you can add headers and footers using inline PHP. Headers and |
---|
173 | footers are added by accessing the PDF renderer directly using inline |
---|
174 | PHP embedded in your HTML file. This is similar to creating PDFs with |
---|
175 | FPDF or ezPDF from R&OS, in that you can draw lines, boxes and text |
---|
176 | directly on the PDF. Here are step by step instructions:</p> |
---|
177 | |
---|
178 | <ol> |
---|
179 | <li> Somewhere in your html file, near the top, open a script tag with a "text/php" type: |
---|
180 | <pre> |
---|
181 | <script type="text/php"> |
---|
182 | </pre> |
---|
183 | </li> |
---|
184 | |
---|
185 | <li> Check if the $pdf variable is set. dompdf sets this variable when evaluating embedded PHP. |
---|
186 | <pre> |
---|
187 | <script type="text/php"> |
---|
188 | |
---|
189 | if ( isset($pdf) ) { |
---|
190 | </pre> |
---|
191 | </li> |
---|
192 | |
---|
193 | <li> Pick a font: |
---|
194 | <pre> |
---|
195 | <script type="text/php"> |
---|
196 | |
---|
197 | if ( isset($pdf) ) { |
---|
198 | |
---|
199 | $font = Font_Metrics::get_font("verdana", "bold"); |
---|
200 | </pre> |
---|
201 | </li> |
---|
202 | |
---|
203 | <li> Use the CPDF_Adapter::page_text() method to set text that will be |
---|
204 | displayed on every page: |
---|
205 | |
---|
206 | <pre> |
---|
207 | <script type="text/php"> |
---|
208 | |
---|
209 | if ( isset($pdf) ) { |
---|
210 | |
---|
211 | $font = Font_Metrics::get_font("verdana", "bold"); |
---|
212 | $pdf->page_text(72, 18, "Fancy Header", $font, 6, array(0,0,0)); |
---|
213 | |
---|
214 | } |
---|
215 | </script> |
---|
216 | </pre> |
---|
217 | |
---|
218 | In this example, the text will be displayed 72pt (1 in) from the left |
---|
219 | edge of the page and 18pt (1/4 in) from the top of the page, in 6pt |
---|
220 | font. The last argument to page_text() is the colour which takes an |
---|
221 | array of the form array(r,g,b) where each of r, g, and b are between |
---|
222 | 0.0 and 1.0. </li> |
---|
223 | |
---|
224 | <li> There are several other methods available. See the API |
---|
225 | documentation for the CPDF_Adapter class (<a |
---|
226 | href="doc/">http://www.digitaljunkies.ca/dompdf/doc</a>) for more |
---|
227 | details. Also have a look at the demo_01.html file in the www/test/ |
---|
228 | directory. It adds a header and footer using |
---|
229 | PDF_Adapter->page_text(). It also adds text superimposed over the |
---|
230 | rendered text using a PDF 'object'. This object is added using |
---|
231 | CPDF_Adapter->add_object(). See <a |
---|
232 | href="usage.php#inline">usage.php</a> for more info on inline PHP.</li> |
---|
233 | </ol> |
---|
234 | |
---|
235 | <a href="#FAQ">[back to top]</a> |
---|
236 | <div class="divider2" style="background-position: 12px 0%"> </div> |
---|
237 | |
---|
238 | <a name="page_break"> </a> |
---|
239 | <h3>How do I insert page breaks?</h3> |
---|
240 | |
---|
241 | <p>Page breaks can be inserted by applying the CSS properties |
---|
242 | <a href="http://www.w3.org/TR/CSS21/page.html#propdef-page-break-before">page-break-before</a> |
---|
243 | and |
---|
244 | <a href="http://www.w3.org/TR/CSS21/page.html#propdef-page-break-after">page-break-after</a> to |
---|
245 | any block level element.</p> |
---|
246 | |
---|
247 | <a href="#FAQ">[back to top]</a> |
---|
248 | <div class="divider1" style="background-position: 44px 0%"> </div> |
---|
249 | |
---|
250 | <a name="zend_optimizer"> </a> |
---|
251 | <h3>I'm getting the following error:<br/> |
---|
252 | Cannot access undefined property for object with |
---|
253 | overloaded property access in |
---|
254 | /var/www/dompdf/include/frame_tree.cls.php on line 160</h3> |
---|
255 | |
---|
256 | <p>This error is caused by an incompatibility with the Zend Optimizer. |
---|
257 | Disable the optimizer when using dompdf.</p> |
---|
258 | |
---|
259 | <a href="#FAQ">[back to top]</a> |
---|
260 | <div class="divider1" style="background-position: 991px 0%"> </div> |
---|
261 | |
---|
262 | <a name="new_window"> </a> |
---|
263 | <h3>How can I make PDFs open in the browser window instead of |
---|
264 | opening the download dialog?</h3> |
---|
265 | |
---|
266 | <p>This is controlled by the "Attachment" header sent by dompdf when |
---|
267 | it streams the PDF to the client. You can modify the headers sent by |
---|
268 | dompdf by passing additional options to the |
---|
269 | <code>$dompdf->stream()</code> function:</p> |
---|
270 | |
---|
271 | <pre> |
---|
272 | require_once("dompdf_config.inc.php"); |
---|
273 | $html = |
---|
274 | '<html><body>'. |
---|
275 | '<p>Some text</p>'. |
---|
276 | '</body></html>'; |
---|
277 | |
---|
278 | $dompdf = new DOMPDF(); |
---|
279 | $dompdf->load_html($html); |
---|
280 | |
---|
281 | $dompdf->render(); |
---|
282 | $domper->stream("my_pdf.pdf", array("Attachment" => 0)); |
---|
283 | |
---|
284 | </pre> |
---|
285 | |
---|
286 | <p>See the <a href="usage.php#methodstream">class reference</a> for full details.</p> |
---|
287 | |
---|
288 | <a href="#FAQ">[back to top]</a> |
---|
289 | <div class="divider2" style="background-position: 237px 0%"> </div> |
---|
290 | |
---|
291 | <a name="centre"> </a> |
---|
292 | <h3>How do I centre a table, paragraph or div?</h3> |
---|
293 | |
---|
294 | <p>You can centre any block level element (table, p, div, ul, etc.) by |
---|
295 | using margins:</p> |
---|
296 | |
---|
297 | <pre> |
---|
298 | <table style="margin-left: auto; margin-right: auto"> |
---|
299 | <tr> |
---|
300 | <td> ... </td> |
---|
301 | </tr> |
---|
302 | </table> |
---|
303 | </pre> |
---|
304 | |
---|
305 | <a href="#FAQ">[back to top]</a> |
---|
306 | <div class="divider1" style="background-position: 884px 0%"> </div> |
---|
307 | |
---|
308 | </div> <?php include "foot.inc" ?> |
---|