faq.php
来自「国外很不错的一个开源OA系统Group-Office」· PHP 代码 · 共 309 行
PHP
309 行
<?php include("head.inc"); ?><a name="FAQ"> </a><h2>Frequently Asked Questions</h2><ol><li><a href="#hello_world">Is there a 'hello world' script for dompdf?</a></li><li><a href="#save">How do I save a PDF to disk?</a></li><li><a href="#dom">I'm getting the following error: <br/> Fatal error: DOMPDF_autoload() [function.require]: Failed opening required '/var/www/dompdf/include/domdocument.cls.php' (include_path='.:') in /var/www/dompdf/dompdf_config.inc.php on line 146</a></li><li><a href="#exec_time">I'm getting the following error: <br/> Fatal error: Maximum execution time of 30 seconds exceeded in /var/www/dompdf/dompdf.php on line XXX</a></li><li><a href="#no_block_parent">I'm getting the following error:<br/>Fatal error: Uncaught exception 'DOMPDF_Exception' with message 'Noblock-level parent found. Not good.' inC:\Program Files\Apache\htdocs\dompdf\include\inline_positioner.cls.php:68...</a></li><li><a href="#tables">I have a big table and it's broken!</a></li><li><a href="#footers">Is there a way to add headers and footers?</a></li><li><a href="#page_break">How do I insert page breaks?</a></li><li><a href="#zend_optimizer">I'm getting the following error:<br/>Cannot access undefined property for object withoverloaded property access in/var/www/dompdf/include/frame_tree.cls.php on line 160</a></li><li><a href="#new_window">How can I make PDFs open in the browser window instead ofopening the download dialog?</a></li><li><a href="#centre">How do I centre a table, paragraph or div?</li></ol><div class="divider1"> </div><div class="answers"><a name="hello_world"> </a><h3>Is there a 'hello world' script for dompdf?</h3><p>Here's a hello world script:<pre><?phprequire_once("dompdf_config.inc.php");$html = '<html><body>'. '<p>Hello World!</p>'. '</body></html>';$dompdf = new DOMPDF();$dompdf->load_html($html);$dompdf->render();$dompdf->stream("hello_world.pdf");?></pre><p>Put this script in the same directory asdompdf_config.inc.php. You'll have to change the paths indompdf_config.inc.php to match your installation.</p><a href="#FAQ">[back to top]</a><div class="divider2" style="background-position: 25% 0%"> </div><a name="save"> </a><h3>How do I save a PDF to disk?</h3><p>If you are using the included <a href="usage.php#web">dompdf.php</a> script youcan pass it the "save_file" option in conjunction with the "output_file" option.</p><p>If you are using the DOMPDF class, you can save the generated PDFby calling <code>$dompdf->output()</code>:</p><pre>require_once("dompdf_config.inc.php");$html = '<html><body>'. '<p>Foo</p>'. '</body></html>';$dompdf = new DOMPDF();$dompdf->load_html($html);$dompdf->render();// The next call will store the entire PDF as a string in $pdf$pdf = $dompdf->output(); // You can now write $pdf to disk, store it in a database or stream it// to the client.file_put_contents("saved_pdf.pdf", $pdf);</pre><p>Note that typically <code>dompdf->stream()</code> and<code>dompdf->output()</code> are mutually exclusive.</p><a href="#FAQ">[back to top]</a><div class="divider1" style="background-position: 721px 0%"> </div><a name="dom"> </a><h3>I'm getting the following error: <br/> Fatal error: DOMPDF_autoload() [function.require]: Failed opening required '/var/www/dompdf/include/domdocument.cls.php' (include_path='.:') in /var/www/dompdf/dompdf_config.inc.php on line 146</h3><p>This error occurs when the version of PHP that you are using does not havethe DOM extension enabled. You can check which extensions are enabled byexamning the output of <code>phpinfo()</code>.</p><p>There are a couple of ways that the DOM extension could have beendisabled. DOM uses libxml, so if libxml is not present on your serverthen the DOM extension will not work. Alternatively, if PHP was compiledwith the '--disable-dom' switch or the '--disable-xml' switch, DOM supportwill also be removed. You can check which switches were used to compilePHP with <code>phpinfo()</code>.</p><a href="#FAQ">[back to top]</a><div class="divider1" style="background-position: 239px 0%"> </div><a name="exec_time"> </a><h3>I'm getting the following error: <br/> Fatal error: Maximum execution time of 30 seconds exceeded in /var/www/dompdf/dompdf.php on line XXX</h3><p>Nested tables are not supported yet (v0.4.3) and can cause dompdf to enter anendless loop, thus giving rise to this error.</p><a href="#FAQ">[back to top]</a><div class="divider1" style="background-position: 300px 0%"> </div><a name="no_block_parent"> </a><h3>I'm getting the following error:<br/>Fatal error: Uncaught exception 'DOMPDF_Exception' with message 'Noblock-level parent found. Not good.' inC:\Program Files\Apache\htdocs\dompdf\include\inline_positioner.cls.php:68...</h3><p>This should be fixed in versions 0.4.1 and up. The error wascaused by <code>parse_url()</code> thinking that the 'c' in 'c:\' wasa protocol. Version 0.4.1 works around this issue.</p><a href="#FAQ">[back to top]</a><div class="divider2" style="background-position: 130px 0%"> </div><a name="tables"> </a><h3>I have a big table and it's broken!</h3><p>This is fixed in versions 0.4 and higher. Previous versions did not support tables that spanned pages.</p><a href="#FAQ">[back to top]</a><div class="divider1" style="background-position: 812px 0%"> </div><a name="footers"> </a><h3>Is there a way to add headers and footers?</h3><p>Yes, you can add headers and footers using inline PHP. Headers andfooters are added by accessing the PDF renderer directly using inlinePHP embedded in your HTML file. This is similar to creating PDFs withFPDF or ezPDF from R&OS, in that you can draw lines, boxes and textdirectly on the PDF. Here are step by step instructions:</p><ol><li> Somewhere in your html file, near the top, open a script tag with a "text/php" type:<pre> <script type="text/php"></pre></li><li> Check if the $pdf variable is set. dompdf sets this variable when evaluating embedded PHP.<pre> <script type="text/php"> if ( isset($pdf) ) {</pre></li><li> Pick a font:<pre> <script type="text/php"> if ( isset($pdf) ) { $font = Font_Metrics::get_font("verdana", "bold");</pre></li><li> Use the CPDF_Adapter::page_text() method to set text that will bedisplayed on every page:<pre> <script type="text/php"> if ( isset($pdf) ) { $font = Font_Metrics::get_font("verdana", "bold"); $pdf->page_text(72, 18, "Fancy Header", $font, 6, array(0,0,0)); } </script></pre>In this example, the text will be displayed 72pt (1 in) from the leftedge of the page and 18pt (1/4 in) from the top of the page, in 6ptfont. The last argument to page_text() is the colour which takes anarray of the form array(r,g,b) where each of r, g, and b are between0.0 and 1.0. </li><li> There are several other methods available. See the APIdocumentation for the CPDF_Adapter class (<ahref="doc/">http://www.digitaljunkies.ca/dompdf/doc</a>) for moredetails. Also have a look at the demo_01.html file in the www/test/directory. It adds a header and footer usingPDF_Adapter->page_text(). It also adds text superimposed over therendered text using a PDF 'object'. This object is added usingCPDF_Adapter->add_object(). See <ahref="usage.php#inline">usage.php</a> for more info on inline PHP.</li></ol><a href="#FAQ">[back to top]</a><div class="divider2" style="background-position: 12px 0%"> </div><a name="page_break"> </a><h3>How do I insert page breaks?</h3><p>Page breaks can be inserted by applying the CSS properties <a href="http://www.w3.org/TR/CSS21/page.html#propdef-page-break-before">page-break-before</a>and <a href="http://www.w3.org/TR/CSS21/page.html#propdef-page-break-after">page-break-after</a> toany block level element.</p><a href="#FAQ">[back to top]</a><div class="divider1" style="background-position: 44px 0%"> </div><a name="zend_optimizer"> </a><h3>I'm getting the following error:<br/>Cannot access undefined property for object withoverloaded property access in/var/www/dompdf/include/frame_tree.cls.php on line 160</h3><p>This error is caused by an incompatibility with the Zend Optimizer.Disable the optimizer when using dompdf.</p><a href="#FAQ">[back to top]</a><div class="divider1" style="background-position: 991px 0%"> </div><a name="new_window"> </a><h3>How can I make PDFs open in the browser window instead ofopening the download dialog?</h3><p>This is controlled by the "Attachment" header sent by dompdf whenit streams the PDF to the client. You can modify the headers sent bydompdf by passing additional options to the<code>$dompdf->stream()</code> function:</p><pre>require_once("dompdf_config.inc.php");$html = '<html><body>'. '<p>Some text</p>'. '</body></html>';$dompdf = new DOMPDF();$dompdf->load_html($html);$dompdf->render();$domper->stream("my_pdf.pdf", array("Attachment" => 0));</pre><p>See the <a href="usage.php#methodstream">class reference</a> for full details.</p><a href="#FAQ">[back to top]</a><div class="divider2" style="background-position: 237px 0%"> </div><a name="centre"> </a><h3>How do I centre a table, paragraph or div?</h3><p>You can centre any block level element (table, p, div, ul, etc.) byusing margins:</p><pre><table style="margin-left: auto; margin-right: auto"><tr><td> ... </td></tr></table></pre><a href="#FAQ">[back to top]</a><div class="divider1" style="background-position: 884px 0%"> </div></div> <?php include "foot.inc"
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?