source: branches/2.2/filemanager/tp/dompdf/www/faq.php @ 3019

Revision 3019, 9.7 KB checked in by amuller, 14 years ago (diff)

Ticket #1135 - Corrigindo CSS e adicionando filemanager

Line 
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/>
22Fatal error: Uncaught exception 'DOMPDF_Exception' with message 'No
23block-level parent found. Not good.' in
24C:\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/>
35Cannot access undefined property for object with
36overloaded 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
41opening 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">&nbsp;</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&lt;?php
54require_once("dompdf_config.inc.php");
55$html =
56    '&lt;html&gt;&lt;body&gt;'.
57    '&lt;p&gt;Hello World!&lt;/p&gt;'.
58    '&lt;/body&gt;&lt;/html&gt;';
59
60$dompdf = new DOMPDF();
61$dompdf-&gt;load_html($html);
62
63$dompdf-&gt;render();
64$dompdf-&gt;stream("hello_world.pdf");
65
66?&gt;
67</pre>
68
69<p>Put this script in the same directory as
70dompdf_config.inc.php.  You'll have to change the paths in
71dompdf_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%">&nbsp;</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
80can 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
83by calling <code>$dompdf-&gt;output()</code>:</p>
84
85<pre>
86require_once("dompdf_config.inc.php");
87$html =
88    '&lt;html&gt;&lt;body&gt;'.
89    '&lt;p&gt;Foo&lt;/p&gt;'.
90    '&lt;/body&gt;&lt;/html&gt;';
91
92$dompdf = new DOMPDF();
93$dompdf-&gt;load_html($html);
94
95$dompdf-&gt;render();
96
97// The next call will store the entire PDF as a string in $pdf
98
99$pdf = $dompdf-&gt;output(); 
100
101// You can now write $pdf to disk, store it in a database or stream it
102// to the client.
103
104file_put_contents("saved_pdf.pdf", $pdf);
105</pre>
106
107<p>Note that typically <code>dompdf-&gt;stream()</code> and
108<code>dompdf-&gt;output()</code> are mutually exclusive.</p>
109
110<a href="#FAQ">[back to top]</a>
111<div class="divider1" style="background-position: 721px 0%">&nbsp;</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
123the DOM extension enabled.  You can check which extensions are enabled by
124examning the output of <code>phpinfo()</code>.</p>
125
126<p>There are a couple of ways that the DOM extension could have been
127disabled.  DOM uses libxml, so if libxml is not present on your server
128then the DOM extension will not work.  Alternatively, if PHP was compiled
129with the '--disable-dom' switch or the '--disable-xml' switch, DOM support
130will also be removed.  You can check which switches were used to compile
131PHP with <code>phpinfo()</code>.</p>
132
133<a href="#FAQ">[back to top]</a>
134<div class="divider1" style="background-position: 239px 0%">&nbsp;</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
142endless 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%">&nbsp;</div>
146
147<a name="no_block_parent"> </a>
148<h3>I'm getting the following error:<br/>
149Fatal error: Uncaught exception 'DOMPDF_Exception' with message 'No
150block-level parent found. Not good.' in
151C:\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
155caused by <code>parse_url()</code> thinking that the 'c' in 'c:\' was
156a 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%">&nbsp;</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%">&nbsp;</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
173footers are added by accessing the PDF renderer directly using inline
174PHP embedded in your HTML file.  This is similar to creating PDFs with
175FPDF or ezPDF from R&amp;OS, in that you can draw lines, boxes and text
176directly 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  &lt;script type="text/php"&gt;
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  &lt;script type="text/php"&gt;
188 
189  if ( isset($pdf) ) {
190</pre>
191</li>
192
193<li> Pick a font:
194<pre>
195  &lt;script type="text/php"&gt;
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
204displayed on every page:
205
206<pre>
207  &lt;script type="text/php"&gt;
208 
209  if ( isset($pdf) ) {
210 
211    $font = Font_Metrics::get_font("verdana", "bold");
212    $pdf-&gt;page_text(72, 18, "Fancy Header", $font, 6, array(0,0,0));
213
214  }
215  &lt;/script&gt;
216</pre>
217
218In this example, the text will be displayed 72pt (1 in) from the left
219edge of the page and 18pt (1/4 in) from the top of the page, in 6pt
220font.  The last argument to page_text() is the colour which takes an
221array of the form array(r,g,b) where each of r, g, and b are between
2220.0 and 1.0.  </li>
223
224<li> There are several other methods available.  See the API
225documentation for the CPDF_Adapter class (<a
226href="doc/">http://www.digitaljunkies.ca/dompdf/doc</a>) for more
227details.  Also have a look at the demo_01.html file in the www/test/
228directory.  It adds a header and footer using
229PDF_Adapter->page_text().  It also adds text superimposed over the
230rendered text using a PDF 'object'.  This object is added using
231CPDF_Adapter->add_object().  See <a
232href="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%">&nbsp;</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>
243and
244<a href="http://www.w3.org/TR/CSS21/page.html#propdef-page-break-after">page-break-after</a> to
245any block level element.</p>
246
247<a href="#FAQ">[back to top]</a>
248<div class="divider1" style="background-position: 44px 0%">&nbsp;</div>
249
250<a name="zend_optimizer"> </a>
251<h3>I'm getting the following error:<br/>
252Cannot access undefined property for object with
253overloaded 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.
257Disable the optimizer when using dompdf.</p>
258
259<a href="#FAQ">[back to top]</a>
260<div class="divider1" style="background-position: 991px 0%">&nbsp;</div>
261
262<a name="new_window"> </a>
263<h3>How can I make PDFs open in the browser window instead of
264opening the download dialog?</h3>
265
266<p>This is controlled by the "Attachment" header sent by dompdf when
267it streams the PDF to the client.  You can modify the headers sent by
268dompdf by passing additional options to the
269<code>$dompdf->stream()</code> function:</p>
270
271<pre>
272require_once("dompdf_config.inc.php");
273$html =
274    '&lt;html&gt;&lt;body&gt;'.
275    '&lt;p&gt;Some text&lt;/p&gt;'.
276    '&lt;/body&gt;&lt;/html&gt;';
277
278$dompdf = new DOMPDF();
279$dompdf-&gt;load_html($html);
280
281$dompdf-&gt;render();
282$domper-&gt;stream("my_pdf.pdf", array("Attachment" =&gt; 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%">&nbsp;</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
295using margins:</p>
296
297<pre>
298&lt;table style="margin-left: auto; margin-right: auto"&gt;
299&lt;tr&gt;
300&lt;td&gt; ... &lt;/td&gt;
301&lt;/tr&gt;
302&lt;/table&gt;
303</pre>
304
305<a href="#FAQ">[back to top]</a>
306<div class="divider1" style="background-position: 884px 0%">&nbsp;</div>
307
308</div> <?php include "foot.inc" ?>
Note: See TracBrowser for help on using the repository browser.