"pdf-o-matic.php": )// and trailer () - provide your own implementation// if you use this script, e.g.://// function// htmldoc_header($title = "") // I - Title string// {// print("$title - Fooware\n");// }//// function// htmldoc_footer()// {// print("\n");// }include_once "../phplib/htmldoc.inc.php4";// Globals...global $_GET; // Form variablesglobal $_SERVER; // Server variablesglobal $PHP_SELF; // Local URL for this page//// 'show_form()' - Show a form for converting a URL to PDF.//functionshow_form(){ global $PHP_SELF; print("

PDF-o-matic is a simple PHP script " ."(view source) " ."that uses HTMLDOC to convert the web page of your choice. " ."Enter a URL to be converted to PDF and click on the " ."Make PDF! button:

\n" ."
\n" ."
" ."\n"); // The following hidden variable fixes a HUGE bug in Microsoft // Internet Explorer (all versions) where MSIE ignores the // Content-Type field and instead uses the "extension" on the // end of the URL... print("" ."
\n"); print("

Please make sure that your HTML code is error free and that all " ."the elements are supported with HTMLDOC. " ."Chapter 6 of the HTMLDOC " ."Users Manual lists the elements that are supported.

\n"); print("
\n" ."" ."" ."" ."\n" ."" ."\n" ."
Server:Dual 2.4GHz Xeon with 2GB RAM running Linux
Status:"); system("ps -A | awk '{print $4}' | grep htmldoc | wc -l"); print("copies of HTMLDOC running
System load average = "); system("uptime | awk '{printf(\"%.2f\", ($10 + $11 + $12) / 3)}'"); print("
\n");}//// 'bad_url()' - See if the URL contains bad characters...//function // O - 1 if the URL is bad, 0 otherwisebad_url($url) // I - URL to check{ // 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("~_*()/:%?+-&@;=,$.0123456789" ."abcdefghijklmnopqrstuvwxyz" ."ABCDEFGHIJKLMNOPQRSTUVWXYZ", $url[$i])) { return (1); } } return (0);} //// 'topdf()' - Convert the named file/URL to PDF.//functiontopdf($filename, // I - File/URL to convert $options = "") // I - Additional command-line options{ # Write the content type to the client... header("Content-Type: application/pdf"); header("Content-Disposition: inline; filename=\"pdf-o-matic.pdf\""); flush(); # Run HTMLDOC to provide the PDF file to the user... # Use the --no-localfiles option for enhanced security! # Use ulimit to limit the maximum amount of memory used by each instance! passthru("ulimit -m 16384; htmldoc --no-localfiles --no-compression -t pdf14 --quiet " ."--jpeg --webpage $options '$filename'");}//// MAIN ENTRY - see if we have form data...//if ($argc && $argv[0] == "source"){ // Show source... print("\n" ."\n" ."Source of PDF-o-matic\n" ."\n" ."\n" ."
\"pdf-o-matic.php\":\n");  highlight_file("pdf-o-matic.php");  print("
\n" ."\n" ."\n");}else if (array_key_exists("URL", $_GET)){ // Yes, see if the URL is a valid URL and not a filename (security...) $url = $_GET["URL"]; $options = ""; if (array_key_exists("HTTPS", $_SERVER) && $_SERVER["HTTPS"] == "on") $self = "https://$_SERVER[HTTP_HOST]$PHP_SELF"; else $self = "http://$_SERVER[HTTP_HOST]$PHP_SELF"; if (bad_url($url)) { // Write the standard header... htmldoc_header("PDF-o-matic"); // Show a form for the URL... show_form(); // Show an error message... print("

Error!

\n" ."

\"$url\" is not a valid URL. Unable to process!

\n"); // Show the standard footer... htmldoc_footer(); } else if (array_key_exists("HTTP_REFERER", $_SERVER) && $self != $_SERVER["HTTP_REFERER"]) { // Write the standard header... htmldoc_header("PDF-o-matic"); // Show an error message - no remote linking! print("

PDF-o-matic

\n" ."

Error!

\n" ."

PDF-o-matic was linked from a remote site, which is " ."not allowed.

\n"); // Show the standard footer... htmldoc_footer(); } else topdf($url, "--header t.D --footer ./. --size letter --left 0.5in");}else{ // Write the standard header... htmldoc_header("PDF-o-matic"); // Show a form for the URL... show_form(); // Show the standard footer... htmldoc_footer();}?> Documento senza titolo