ID's para los comboboxes
[ecomupi.git] / include / dompdf / dompdf.php
blob644dd27814d6140339adb2e4205cd5b9a91f464d
1 <?php
2 /**
3 * DOMPDF - PHP5 HTML to PDF renderer
5 * File: $RCSfile: dompdf.php,v $
6 * Created on: 2004-06-22
8 * Copyright (c) 2004 - Benj Carson <benjcarson@digitaljunkies.ca>
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with this library in the file LICENSE.LGPL; if not, write to the
22 * Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
23 * 02111-1307 USA
25 * Alternatively, you may distribute this software under the terms of the
26 * PHP License, version 3.0 or later. A copy of this license should have
27 * been distributed with this file in the file LICENSE.PHP . If this is not
28 * the case, you can obtain a copy at http://www.php.net/license/3_0.txt.
30 * The latest version of DOMPDF might be available at:
31 * http://www.digitaljunkies.ca/dompdf
33 * dompdf.php is a simple script to drive DOMPDF. It can be executed from
34 * a browser or from the command line.
36 * @link http://www.digitaljunkies.ca/dompdf
37 * @copyright 2004 Benj Carson
38 * @author Benj Carson <benjcarson@digitaljunkies.ca>
39 * @package dompdf
40 * @version 0.5.1
43 /* $Id: dompdf.php,v 1.17 2006/07/07 21:31:02 benjcarson Exp $ */
45 /**
46 * Display command line usage:
48 * Usage: ./dompdf.php [options] html_file
50 * html_file can be a filename, a url if fopen_wrappers are enabled, or the '-'
51 * character to read from standard input.
53 * Options:
54 * -h Show this message
55 * -l list available paper sizes
56 * -p size paper size; something like 'letter', 'A4', 'legal', etc. The default is
57 * 'letter'
58 * -o orientation either 'portrait' or 'landscape'. Default is 'portrait'.
59 * -b path set the 'document root' of the html_file. Relative urls (for
60 * stylesheets) are resolved using this directory. Default is the
61 * directory of html_file.
62 * -f file the output filename. Default is the input [html_file].pdf.
63 * -v verbose: display html parsing warnings and file not found errors.
64 * -d very verbose: display oodles of debugging output: every frame in the
65 * tree is printed to stdout.
70 function dompdf_usage() {
71 echo
72 "\nUsage: {$_SERVER["argv"][0]} [options] html_file\n\n".
73 "html_file can be a filename, a url if fopen_wrappers are enabled, or the '-' \n".
74 "character to read from standard input.\n\n".
75 "Options:\n".
76 " -h\t\tShow this message\n".
77 " -l\t\tlist available paper sizes\n".
78 " -p size\tpaper size; something like 'letter', 'A4', 'legal', etc. The default is\n".
79 " \t\t'" . DOMPDF_DEFAULT_PAPER_SIZE . "'\n".
80 " -o orientation\teither 'portrait' or 'landscape'. Default is 'portrait'.\n".
81 " -b path\tset the 'document root' of the html_file. Relative urls (for \n".
82 " \tstylesheets) are resolved using this directory. Default is the \n".
83 " \tdirectory of html_file.\n".
84 " -f file\tthe output filename. Default is the input [html_file].pdf.\n".
85 " -v \tverbose: display html parsing warnings and file not found errors.\n".
86 " -d \tvery verbose: display oodles of debugging output: every frame\n".
87 " \tin the tree printed to stdout.\n\n";
91 function getoptions() {
93 $opts = array();
95 if ( $_SERVER["argc"] == 1 )
96 return $opts;
98 $i = 1;
99 while ($i < $_SERVER["argc"]) {
101 switch ($_SERVER["argv"][$i]) {
103 case "--help":
104 case "-h":
105 $opts["h"] = true;
106 $i++;
107 break;
109 case "-l":
110 $opts["l"] = true;
111 $i++;
112 break;
114 case "-p":
115 if ( !isset($_SERVER["argv"][$i+1]) )
116 die("-p switch requires a size parameter\n");
117 $opts["p"] = $_SERVER["argv"][$i+1];
118 $i += 2;
119 break;
121 case "-o":
122 if ( !isset($_SERVER["argv"][$i+1]) )
123 die("-o switch requires an orientation parameter\n");
124 $opts["o"] = $_SERVER["argv"][$i+1];
125 $i += 2;
126 break;
128 case "-b":
129 if ( !isset($_SERVER["argv"][$i+1]) )
130 die("-b switch requires an path parameter\n");
131 $opts["b"] = $_SERVER["argv"][$i+1];
132 $i += 2;
133 break;
135 case "-f":
136 if ( !isset($_SERVER["argv"][$i+1]) )
137 die("-f switch requires an filename parameter\n");
138 $opts["f"] = $_SERVER["argv"][$i+1];
139 $i += 2;
140 break;
142 case "-v":
143 $opts["v"] = true;
144 $i++;
145 break;
147 case "-d":
148 $opts["d"] = true;
149 $i++;
150 break;
152 default:
153 $opts["filename"] = $_SERVER["argv"][$i];
154 $i++;
155 break;
159 return $opts;
162 require_once("dompdf_config.inc.php");
163 global $_dompdf_show_warnings;
164 global $_dompdf_debug;
166 $old_limit = ini_set("memory_limit", "80M");
168 $sapi = php_sapi_name();
170 switch ( $sapi ) {
172 case "cli":
174 $opts = getoptions();
176 if ( isset($opts["h"]) || (!isset($opts["filename"]) && !isset($opts["l"])) ) {
177 dompdf_usage();
178 exit;
181 if ( isset($opts["l"]) ) {
182 echo "\nUnderstood paper sizes:\n";
184 foreach (array_keys(CPDF_Adapter::$PAPER_SIZES) as $size)
185 echo " " . mb_strtoupper($size) . "\n";
186 exit;
188 $file = $opts["filename"];
190 if ( isset($opts["p"]) )
191 $paper = $opts["p"];
192 else
193 $paper = DOMPDF_DEFAULT_PAPER_SIZE;
195 if ( isset($opts["o"]) )
196 $orientation = $opts["o"];
197 else
198 $orientation = "portrait";
200 if ( isset($opts["b"]) )
201 $base_path = $opts["b"];
203 if ( isset($opts["f"]) )
204 $outfile = $opts["f"];
205 else {
206 if ( $file == "-" )
207 $outfile = "dompdf_out.pdf";
208 else
209 $outfile = str_ireplace(array(".html", ".htm", ".php"), "", $file) . ".pdf";
212 if ( isset($opts["v"]) )
213 $_dompdf_show_warnings = true;
215 if ( isset($opts["d"]) ) {
216 $_dompdf_show_warnings = true;
217 $_dompdf_debug = true;
220 $save_file = true;
222 break;
224 default:
226 if ( isset($_GET["input_file"]) )
227 $file = rawurldecode($_GET["input_file"]);
228 else
229 throw new DOMPDF_Exception("An input file is required (i.e. input_file _GET variable).");
231 if ( isset($_GET["paper"]) )
232 $paper = rawurldecode($_GET["paper"]);
233 else
234 $paper = DOMPDF_DEFAULT_PAPER_SIZE;
236 if ( isset($_GET["orientation"]) )
237 $orientation = rawurldecode($_GET["orientation"]);
238 else
239 $orientation = "portrait";
241 if ( isset($_GET["base_path"]) )
242 $base_path = rawurldecode($_GET["base_path"]);
244 if ( isset($_GET["output_file"]) )
245 $outfile = rawurldecode($_GET["output_file"]);
246 else
247 $outfile = "dompdf_out.pdf";
249 if ( isset($_GET["save_file"]) )
250 $save_file = true;
251 else
252 $save_file = false;
254 break;
257 $dompdf = new DOMPDF();
259 if ( $file == "-" ) {
260 $str = "";
261 while ( !feof(STDIN) )
262 $str .= fread(STDIN, 4096);
264 $dompdf->load_html($str);
266 } else
267 $dompdf->load_html_file($file);
269 if ( isset($base_path) ) {
270 $dompdf->set_base_path($base_path);
273 $dompdf->set_paper($paper, $orientation);
275 $dompdf->render();
277 if ( $_dompdf_show_warnings ) {
278 foreach ($_dompdf_warnings as $msg)
279 echo $msg . "\n";
280 flush();
283 if ( $save_file ) {
284 // if ( !is_writable($outfile) )
285 // throw new DOMPDF_Exception("'$outfile' is not writable.");
286 if ( strtolower(DOMPDF_PDF_BACKEND) == "gd" )
287 $outfile = str_replace(".pdf", ".png", $outfile);
289 file_put_contents($outfile, $dompdf->output());
290 exit(0);
293 if ( !headers_sent() ) {
294 $dompdf->stream($outfile);