📄 usage.php
字号:
<?php include("head.inc"); ?><div id="toc"><h2>On this page:</h2><ul><?php echo li_arrow() ?><a href="#usage">Usage</a></li><ul><?php echo li_arrow() ?><a href="#web">Invoking via the web</a></li> <?php echo li_arrow() ?><a href="#cli">Invoking via the command line</a></li> <?php echo li_arrow() ?><a href="#class">Using the dompdf class directly</a></li> <?php echo li_arrow() ?><a href="#method_summary">dompdf class reference</a></li> </ul><?php echo li_arrow() ?><a href="#inline">Inline PHP support</a></li></ul></div><a name="usage"> </a><h2>Usage</h2><p>The dompdf.php script included in the distribution can be used both fromthe <a href="#cli">command line</a> or via a <a href="#web">web browser</a>.Alternatively, the dompdf class can be used <a href="#class">directly</a>.</p><a name="web"> </a><h3>Invoking dompdf via the web</h3><p>The dompdf.php script is not intended to be an interactive page. Itreceives input parameters via $_GET and can stream a PDF directly to thebrowser. This makes it possible to embed links to the script in a page thatlook like static PDF links, but are actually dynamically generated. Thismethod is also useful as a redirection target.</p><p>dompdf.php accepts the following $_GET variables:</p><table><tr><td class="bar1" colspan="3"> </td></tr><tr><td class="input">input_file</td> <td>required</td><td class="description">a rawurlencoded() path to the HTML file to process. Remote files(http/ftp) are supported if fopen wrappers are enabled.</td></tr><tr><td class="input">paper</td> <td>optional</td><td class="description">the paper size. Defaults to 'letter' (unless the default has beenchanged in dompdf_config.inc.php). See include/pdf_adapter.cls.php, orinvoke dompdf.php on the command line with the -l switch for accepted papersizes.</td></tr><tr><td class="input">orientation</td> <td>optional</td><td class="description">'portrait' or 'landscape'. Defaults to 'portrait'.</td></tr><tr><td class="input">base_path</td> <td>optional</td><td class="description">the base path to use when resolving relative links (images or CSSfiles). Defaults to the directory containing the file being accessed.(This option is useful for pointing dompdf at your CSS files even though theHTML file may be elsewhere.)</td></tr><tr><td class="input">output_file</td> <td>optional</td><td class="description">the rawurlencoded() name of the output file. Defaults to 'dompdf_out.pdf'.</td></tr><tr><td class="input">save_file</td> <td>optional</td><td class="description">If present (i.e. <code>isset($_GET["save_file"]) == true');</code>),output_file is saved locally, Otherwise the file is streamed directly to the client.</td></tr><tr><td class="bar2" colspan="3"> </td></tr></table><p>One technique for generating dynamic PDFs is to generate dynamic HTML as younormally would, except instead of displaying the output to the browser, youuse output buffering and write the output to a temporary file. Once thisfile is saved, you redirect to the dompdf.php script. If you use atemplating engine like Smarty, you can simply do:</p><pre><?php$tmpfile = tempnam("/tmp", "dompdf_");file_put_contents($tmpfile, $smarty->fetch()); // Replace $smarty->fetch() // with your HTML string$url = "dompdf.php?input_file=" . rawurlencode($tmpfile) . "&paper=letter&output_file=" . rawurlencode("My Fancy PDF.pdf");header("Location: http://" . $_SERVER["HTTP_HOST"] . "/$url");?></pre><p>If you use any stylesheets, you may need to provide the<code>base_path</code> option to tell dompdf where to look for them, as theyare not likely relative to /tmp ;).</p><a name="cli"> </a><h3>Invoking dompdf via the command line</h3><p>You can execute dompdf.php using the following command:</p><pre>$ php -f dompdf.php -- [options]</pre><p>(If you find yourself using only the cli interface, you can add<code>#!/usr/bin/php</code> as the first line of dompdf.php to invoke dompdf.phpdirectly.)</p><p>dompdf.php is invoked as follows:</p><table><tr><td class="bar1" colspan="2"> </td></tr><tr><td colspan="2" class="input">$ ./dompdf.php [options] html_file</td></tr><tr><td colspan="2"><code>html_file</code> can be a filename, a url iffopen_wrappers are enabled, or the '-' character to read from standard input.</td></tr><tr><td class="input">-h</td><td class="description">Show a brief help message</td></tr><tr><td class="input">-l</td><td class="description">list available paper sizes</td></tr><tr><td class="input">-p size</td><td class="description">paper size; something like 'letter', 'A4', 'legal', etc. Thee default is 'letter'</td></tr><tr><td class="input">-o orientation</td><td class="description">either 'portrait' or 'landscape'. Default is 'portrait'.</td></tr><tr><td class="input">-b path</td><td class="description">the base path to use when resolving relative links(images or CSS files). Default is the directory of html_file.</td></tr><tr><td class="input">-f file</td><td class="description">the output filename. Default is the input <code>[html_file].pdf</code>.</td></tr><tr><td class="input">-v</td><td class="description">verbose: display html parsing warnings and file not found errors.</td></tr><tr><td class="input">-d</td><td class="description">very verbose: display oodles of debugging output;every frame in the tree is printed to stdout.</td></tr><tr><td class="bar2" colspan="2"> </td></tr></table><p>Examples:</p><pre>$ php -f dompdf.php -- my_resume.html$ ./dompdf.php -b /var/www/ ./web_stuff/index.html$ echo '<html><body>Hello world!</body></html>' | ./dompdf.php -</pre><a name="class"> </a><h3>Using the dompdf class directly</h3><p>Using the dompdf class directly is fairly straightforward:<pre><?phprequire_once("dompdf_config.inc.php");$html = '<html><body>'. '<p>Put your html here, or generate it with your favourite '. 'templating system.</p>'. '</body></html>';$dompdf = new DOMPDF();$dompdf->load_html($html);$dompdf->render();$dompdf->stream("sample.pdf");?></pre></p><p>Below is a summary of the methods available in the dompdf class. For complete details,see the <a href="http://www.digitaljunkies.ca/dompdf/doc/">APIdocumentation</a> for the class interface definition.</p><a name="method_summary"> </a><h3>Method Summary</h3><ul class="method-summary"><?php echo li_arrow() ?><span class="method-result">DOMPDF</span> <a href="#method__construct">__construct</a>()</li><?php echo li_arrow() ?><span class="method-result">string</span> <a href="#methodget_base_path">get_base_path</a>()</li><?php echo li_arrow() ?><span class="method-result">string</span> <a href="#methodget_host">get_host</a>()</li><?php echo li_arrow() ?><span class="method-result">string</span> <a href="#methodget_protocol">get_protocol</a>()</li><?php echo li_arrow() ?><span class="method-result">Frame_Tree</span> <a href="#methodget_tree">get_tree</a>()</li><?php echo li_arrow() ?><span class="method-result">void</span> <a href="#methodload_html">load_html</a>(<span class="var-type">string</span> <span class="var-name">$str</span>)</li><?php echo li_arrow() ?><span class="method-result">void</span> <a href="#methodload_html_file">load_html_file</a>(<span class="var-type">string</span> <span class="var-name">$file</span>)</li><?php echo li_arrow() ?><span class="method-result">string</span> <a href="#methodoutput">output</a>()</li><?php echo li_arrow() ?><span class="method-result">void</span> <a href="#methodrender">render</a>()</li><?php echo li_arrow() ?><span class="method-result">void</span> <a href="#methodset_base_path">set_base_path</a>(<span class="var-type">string</span> <span class="var-name">$path</span>)</li><?php echo li_arrow() ?><span class="method-result">void</span> <a href="#methodset_host">set_host</a>(<span class="var-type">string</span> <span class="var-name">$host</span>)</li><?php echo li_arrow() ?><span class="method-result">void</span> <a href="#methodset_paper">set_paper</a>(<span class="var-type">string</span> <span class="var-name">$size</span>, [<span class="var-type">string</span> <span class="var-name">$orientation</span> = "portrait"])</li><?php echo li_arrow() ?><span class="method-result">void</span> <a href="#methodset_protocol">set_protocol</a>(<span class="var-type">string</span> <span class="var-name">$proto</span>)</li><?php echo li_arrow() ?><span class="method-result">void</span> <a href="#methodstream">stream</a>(<span class="var-type">string</span> <span class="var-type">$filename</span>, [<span class="var-type">mixed</span> <span class="var-name">$options</span> = null])</li></ul><div class="method-definition" style="background-position: 10px bottom;"><a name="method__construct" id="__construct"><!-- --></a><div class="method-header"> <span class="method-title">Constructor __construct</span> (line <span class="line-number">163</span>)</div> <p class="short-description">Class constructor</p> <div class="method-signature"> <span class="method-result">DOMPDF</span> <span class="method-name">__construct</span>() </div></div><div class="method-definition" style="background-position: 302px bottom;"><a name="methodget_base_path" id="get_base_path"><!-- --></a><div class="method-header"> <span class="method-title">get_base_path</span> (line <span class="line-number">227</span>)</div> <p class="short-description">Returns the base path</p> <div class="method-signature"> <span class="method-result">string</span> <span class="method-name">get_base_path</span>() </div></div><div class="method-definition" style="background-position: 710px bottom;"><a name="methodget_canvas" id="get_canvas"><!-- --></a><div class="method-header"> <span class="method-title">get_canvas</span> (line <span class="line-number">234</span>)</div> <p class="short-description">Return the underlying Canvas instance (e.g. CPDF_Adapter, GD_Adapter)</p> <div class="method-signature"> <span class="method-result">Canvas</span> <span class="method-name">get_canvas</span>() </div></div>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -