function dompdf_usage() {
$default_paper_size = DOMPDF_DEFAULT_PAPER_SIZE;
echo <<<EOD
Usage: {$_SERVER["argv"][0]} [options] html_file
html_file can be a filename, a url if fopen_wrappers are enabled, or the '-' character to read from standard input.
Options:
-h Show this message
-l List available paper sizes
-p size Paper size; something like 'letter', 'A4', 'legal', etc.
The default is '$default_paper_size'
-o orientation Either 'portrait' or 'landscape'. Default is 'portrait'
-b path Set the 'document root' of the html_file.
Relative urls (for stylesheets) are resolved using this directory.
Default is the directory of html_file.
-f file The output filename. Default is the input [html_file].pdf
-v Verbose: display html parsing warnings and file not found errors.
-d Very verbose: display oodles of debugging output: every frame
in the tree printed to stdout.
-t Comma separated list of debugging types (page-break,reflow,split)
EOD;
exit;
}
$sapi = php_sapi_name();
$options = array();
switch ( $sapi ) {
case "cli":
$opts = getoptions();
if ( isset($opts["h"]) || (!isset($opts["filename"]) && !isset($opts["l"])) ) {
dompdf_usage();
exit;
}
- -
if ( isset($opts["l"]) ) {
echo "\nUnderstood paper sizes:\n";
foreach (array_keys(CPDF_Adapter::$PAPER_SIZES) as $size)
echo " " . mb_strtoupper($size) . "\n";
exit;
}
$file = $opts["filename"];
if ( isset($opts["p"]) )
$paper = $opts["p"];
else
$paper = DOMPDF_DEFAULT_PAPER_SIZE;
if ( isset($opts["o"]) )
$orientation = $opts["o"];
else
$orientation = "portrait";
- -
$dompdf = new DOMPDF();
if ( $file === "-" ) {
$str = "";
while ( !feof(STDIN) )
$str .= fread(STDIN, 4096);
$dompdf->load_html($str);
} else
$dompdf->load_html_file($file);
if ( isset($base_path) ) {
$dompdf->set_base_path($base_path);
}
$dompdf->set_paper($paper, $orientation);
$dompdf->render();
if ( $_dompdf_show_warnings ) {
global $_dompdf_warnings;
foreach ($_dompdf_warnings as $msg)
echo $msg . "\n";
echo $dompdf->get_canvas()->get_cpdf()->messages;
flush();
}
$dompdf = new DOMPDF();
$dompdf->load_html_file("dompdf/output/" . $outputFile);
$dompdf->render();
$outputPDF = $dompdf->output();
file_put_contents($_REQUEST['folder'] . '/' . $firstRecipe . '.pdf', $outputPDF);
} else {
//clear all the output, nothing will be displayed.
if($pdf) ob_end_clean();
//Generate unique file name, time() gives
//current time in milliseconds so it is always different
$outputFile = time() . ".html";
file_put_contents("dompdf/output/" . $outputFile, $output);
//now lets redirect to the PDF converter!
//You can change some settings for the PDF viewer in the URL:
$url = "dompdf/dompdf.php?base_path=output%2F&options[Attachment]=0&input_file=" . $outputFile . "#toolbar=1&view=FitW&statusbar=1&messages=0&navpanes=1";
if($pdf) header("Location: $url");
}
$dompdf->load_html_file("dompdf/output/" . $outputFile);
// *OR* if you have HTML $dompdf->load_html($output);
$dompdf->set_paper(array(288,432,0,0));
$dompdf->render();
$dompdf->stream('document.pdf');
<?php require_once("dompdf/dompdf_config.inc.php"); ?>
<?php
$dompdf = new DOMPDF();
$html =
'<html><body>'.
'<p>Sample html.</p>'.
'</body></html>';
$dompdf->load_html($html);
//$dompdf->set_paper(array(288,432,0,0));
$dompdf->render();
$dompdf->stream("sample.pdf");
?>
Fatal error: Uncaught exception 'DOMPDF_Exception' with message 'Box property calculation requires containing block width' in [my internal filepath]/dompdf/include/block_frame_reflower.cls.php:171.
block_frame_reflower.cls.php
php file, and it looks like the $w variable isn't
getting set. I am not sure how that is supposed to work. What am I
missing?