// // Sample "portal" script to convert the named HTML file to PDF on-the-fly. // // Usage: http://www.domain.com/path/topdf.php/path/filename.html // // // 'topdf()' - Convert the named file/URL to PDF. // function topdf($filename, $options = "") { # global $_SERVER['REQUEST_URI']; $myname=str_replace("/","",basename($_SERVER['REQUEST_URI'])); $myname=str_replace("pdftemplates","",$myname); $myname=str_replace(".php","",$myname); # Write the content type to the client... header("Content-Type: application/pdf"); header('Content-Disposition: attachment; filename="' . $myname . '.pdf"'); flush(); # Run HTMLDOC to provide the PDF file to the user... passthru("/usr/bin/htmldoc -t pdf --browserwidth 760 --continuous --size Universal --quiet --bodyfont Helvetica --header ... --footer ... --headfootfont Helvetica --headfootsize 6 --jpeg --fontsize 9 --linkstyle plain '$filename'"); #print("/usr/bin/htmldoc -t pdf --continuous --no-compression --no-localfiles --size Universal --quiet --jpeg --webpage '$filename'"); } // // 'bad_url()' - See if the URL contains bad characters... // function bad_url($url) { // See if the URL starts with http: or https:... if (strncmp($url, "http://", 7) != 0 && strncmp($url, "https://", 8) != 0) { return 1; } // Check for bad characters in the URL... $len = strlen($url); for ($i = 0; $i < $len; $i ++) { if (!strchr("~_*()/:%?+-][&@;=,$.", $url[$i]) && !ctype_alnum($url[$i])) { return 1; } } return 0; } // // MAIN ENTRY - Pass the trailing path info in to HTMLDOC... // #global $_SERVER['SERVER_NAME']; #global $_SERVER['SERVER_PORT']; #global $_SERVER['REQUEST_URI']; #global $_SERVER['QUERY_STRING']; #$pageid=str_replace("/","",$REQUEST_URI); $templatesfolder="/pdftemplates"; if ($_SERVER['QUERY_STRING'] != "") { $url = "http://${_SERVER['SERVER_NAME']}:{$_SERVER['SERVER_PORT']}${templatesfolder}${_SERVER['REQUEST_URI']}?${_SERVER['QUERY_STRING']}"; } else { $url = "http://${_SERVER['SERVER_NAME']}:${_SERVER['SERVER_PORT']}${templatesfolder}/".basename($_SERVER['REQUEST_URI']); } if (bad_url($url)) { print("
The URL $url is bad.
\n" ."\n"); } else { #echo $url; #exit; topdf($url); } ?>