Home about IT Motivation Course Sales Project About Me

Sunday, March 08, 2009

create report PHP - Crystal Report - PDF at Ms SQL Server

<?php
$myCrystal = new COM("CrystalRuntime.Application");// or die("Unable to create Application COM object");

$myReport =& $myCrystal->OpenReport(getcwd()."\\".$_GET["f"]);

$myDBSObj =& $myReport->Database;
$myOption =& $myReport->ExportOptions;
$myParams =& $myReport->ParameterFields;

$myDBSObj->LogOnServer("PDSODBC.DLL", "DSN name", "database name", "sa", "password");

$myOption->DestinationType = 1;
$myOption->FormatType = 31;

if (isset($_GET["p"]))
for ($i = 1; $i <= count($_GET["p"]); $i++) {
$myParam = $myParams->Item($i);
//echo $myParam->Name;
$myParam->AddCurrentValue($_GET["p"][$i]);
//echo $_GET["p"][$i];
//echo $myParam->IsCurrentValueSet;
//echo $myParam->Value;
}

$DiskFileName = getcwd()."\\".current(explode(".",$_GET["f"])).".pdf";
$myReport->ExportOptions->DiskFileName = $DiskFileName;

$myReport->Export(FALSE);

$strFile = file_get_contents($DiskFileName);
//unlink($DiskFileName);
$lenFile = strlen($strFile);

header("Content-type: application/pdf");
header("Content-Length: " . $lenFile);
header("Content-Disposition: inline; filename=".current(explode(".",$_GET["f"])).".pdf");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Pragma: public");

print($strFile);

?>

DSN --> setting at ODBC window and Crystal report setting. Please make sure that DSN name should be same between above script, DSN windows name and seeting DSN at Crystal Report.

1 comment:

odon95 said...

Trims Mas. Setelah muter2 googling berminggu2 akhirnya nemu blog ini. Makasi banyak mas.

doni.bageur