Creating PDFs With Code Charge Studio
Creating PDFs With Code Charge Studio
Creating PDFs With Code Charge Studio
This document will provide you some insight into creating your own reports, output as PDF files, from CodeCharge pages. Actually, the process works for any URL want to capture. There is a very powerful set of functions available as GPL'd code. Most of what you need will be installed and ready to go if your webserver is Linux. I set this up on a Fedora Core distribution from RedHat and it was extremely easy. Only the outer "wrapper" from http://www.rustyparts.com was missing - everything else is in the Fedora distribution.
2004, Donald N. Bevis for GoToDon.com Permission is granted to distribute freely as long as this copyright notice is retained in it's entirety without modification. Ownership of this document remains with the copyright holder. Improvements or corrections are welcomed. See http://www.GoToDon.Com/ccbth for contact information. This document is available for download from the aforementioned location
The code called by the Run Report button is shown below. It is mostly unchanged from the example provided at rustyparts.com. I just pasted it into the event code-file for my report page.
2004, Donald N. Bevis for GoToDon.com Permission is granted to distribute freely as long as this copyright notice is retained in it's entirety without modification. Ownership of this document remains with the copyright holder. Improvements or corrections are welcomed. See http://www.GoToDon.Com/ccbth for contact information. This document is available for download from the aforementioned location
// remove old one, just to make sure we are making it afresh @unlink($pdfFile);
$pdf->setTmpDir(dirname('__FILE__') .'/reports/pdf/tmp/');
// Control the output of additional debug information $pdf->setDebug(false); // When 'true' this dumps tracing info to the browser while the conversion to PDF executes
// set that we do want to use the page's css $pdf->setUseCSS(true); // give it our own css, in this case it will make it so // the lines are double spaced $pdf->setAdditionalCSS(' p { line-height: 1.8em; font-size: 12pt; }'); // don't want to underline hyperlinks $pdf->setUnderlineLinks(false); // scale the page down slightly, just seems to fit the page better $pdf->setScaleFactor('.9'); // make the page black and light $pdf->setUseColor(false);
2004, Donald N. Bevis for GoToDon.com Permission is granted to distribute freely as long as this copyright notice is retained in it's entirety without modification. Ownership of this document remains with the copyright holder. Improvements or corrections are welcomed. See http://www.GoToDon.Com/ccbth for contact information. This document is available for download from the aforementioned location
2004, Donald N. Bevis for GoToDon.com Permission is granted to distribute freely as long as this copyright notice is retained in it's entirety without modification. Ownership of this document remains with the copyright holder. Improvements or corrections are welcomed. See http://www.GoToDon.Com/ccbth for contact information. This document is available for download from the aforementioned location
// $hostdomain = "localhost"; are not on a different server // Change this if the reports
// Invoke the report-generator object to produce the PDF copy of our report URL
// The list of POST parameters here must correspond to each of the form fields that accept user input // By convention, all .php report files are designed to recognize parameters // by the names cid, pid, yr,st and en $sep = "?"; $temp = CCGetFromPost("cid","0"); if ($temp !== "0") { $params = $params . $sep . "cid=" . $temp; $sep = "&"; }
$temp = CCGetFromPost("List_Ppty","0"); if ($temp !== "0") { $params = $params . "&pid=" . $temp; $sep = "&"; }
2004, Donald N. Bevis for GoToDon.com Permission is granted to distribute freely as long as this copyright notice is retained in it's entirety without modification. Ownership of this document remains with the copyright holder. Improvements or corrections are welcomed. See http://www.GoToDon.Com/ccbth for contact information. This document is available for download from the aforementioned location
$temp = CCGetFromPost("Text_Year","0000"); if ($temp !== "0") { $params = $params . "&yr=" . $temp; $sep = "&"; }
$temp = CCGetFromPost("Text_From","0000"); if ($temp !== "0") { $params = $params . "&st=" . $temp; $sep = "&"; }
$temp = CCGetFromPost("Text_To","0000"); if ($temp !== "0") { $params = $params . "&en=" . $temp; $sep = "&"; }
//
Determine where the output file will be stored $rptpath = "/uploads/" . CCGetParam("cid","0") . "/";
//
Create the output filename based on the reportname field $filename = $reports->reportname->GetValue() . ".pdf";
// Ensure the file does not exist, append a number to it until we create a unique file name // This is the same algorithm as used by the FileUpload class
$file_exists = true; $index = 0; while($file_exists) { $ActualFileName = dirname(__FILE__) . $rptpath . date("YmdHis") . $index . "." . $filename;
2004, Donald N. Bevis for GoToDon.com Permission is granted to distribute freely as long as this copyright notice is retained in it's entirety without modification. Ownership of this document remains with the copyright holder. Improvements or corrections are welcomed. See http://www.GoToDon.Com/ccbth for contact information. This document is available for download from the aforementioned location
$output_file = $ActualFileName;
$report_URL = $reports->new_URL->GetValue();
// Construction the URL of the report to be run by combining the URI of the report with the query parameters if (strcasecmp(substr($report_URL,1,5),"http:") == 0) {
if (substr($report_URL,1,1) !== "/") { $report_URL = "/" . $report_URL; } $report_URL = ServerURL . "reports" . $report_URL . ".php" . $params; }
//
// // Determine whether the report ran correctly or not if (file_exists($output_file)) { // Temporarily store the filename and callback this php page with a parameter so it displays the "reportlog" form CCSetSession("last_report_path",$output_file); CCSetSession("last_report_URL",$last_report_URL);
2004, Donald N. Bevis for GoToDon.com Permission is granted to distribute freely as long as this copyright notice is retained in it's entirety without modification. Ownership of this document remains with the copyright holder. Improvements or corrections are welcomed. See http://www.GoToDon.Com/ccbth for contact information. This document is available for download from the aforementioned location
2004, Donald N. Bevis for GoToDon.com Permission is granted to distribute freely as long as this copyright notice is retained in it's entirety without modification. Ownership of this document remains with the copyright holder. Improvements or corrections are welcomed. See http://www.GoToDon.Com/ccbth for contact information. This document is available for download from the aforementioned location