This is an archived forum post. The information may be outdated. Contact us if you have any questions.
require 'pdfcrowd.php'; try { // build the url and remove the pdf field from the query string $url = "http://" . $_SERVER["SERVER_NAME"] . $_SERVER["PHP_SELF"]; if (count($_GET) > 1) { unset($_GET["pdf"]); $url = $url . "?" . http_build_query($_GET, '', '&'); } // call the API $client = new Pdfcrowd("***", "***"); $pdf = $client->convertURI($url); // send the generated pdf to the browser header("Content-Type: application/pdf"); header("Cache-Control: no-cache"); header("Accept-Ranges: none"); header("Content-Disposition: attachment; filename=\"Invoice-ID-$filename.pdf\""); echo $pdf; } catch(PdfcrowdException $why) { echo "Pdfcrowd Error: " . $why; }
if ($_GET["pdf"]) { try { // remove the pdf field from the url $url = "http://" . $_SERVER["SERVER_NAME"] . $_SERVER["PHP_SELF"]; if (count($_GET) > 1) { unset($_GET["pdf"]); $url = $url . "?" . http_build_query($_GET, '', '&'); } // call the API $client = new Pdfcrowd("***", "***"); $pdf = $client->convertURI($url); // send the generated pdf to the browser header("Content-Type: application/pdf"); header("Cache-Control: no-cache"); header("Accept-Ranges: none"); header("Content-Disposition: attachment; filename=\"Invoice-ID-$filename.pdf\""); echo $pdf; } catch(PdfcrowdException $why) { echo "Pdfcrowd Error: " . $why; } // do not render the HTML page, stop here return; } else { // render your HTML page here ... }