|
-
Dec 24th, 2009, 01:33 AM
#1
Thread Starter
New Member
Crystal Reports issue with PHP
Hi
Im using wamp version 2.0 in my windows machine. I want to use crystal reports with a php project. I tried the below php code to use crystal reports but its throwing exceptions. Please give me a solution.
The php code is :
<?php
try
{
$reportName = "C:\\Report1.rpt";
$my_pdf = "C:\\Report1.pdf";
set_time_limit(300);
$ObjectFactory= new COM("CrystalReports11.ObjectFactory.1");
// Register the typelibrary. and must place here, otherwise it won't run the next code
com_load_typelib('CrystalDesignRunTime.Application');
$crapp = $ObjectFactory->CreateObject("CrystalDesignRunTime.Application");
$creport = $crapp->OpenReport($reportName, 1); //waiting for localhost very long here, i wonder why, so i can't proceed the next code.
//exit;
$creport->EnableParameterPrompting = 0;
$creport->DiscardSavedData;
$creport->ReadRecords();
for($i=1;$i<=count($vals);$i++){
$field=$creport->ParameterFields($i);
$res=@$field->SetCurrentValue($vals[$i]);
if($res==0){
//success setting parameter value
}else{
return "Failed to create report. Failed to set parameter $i with value ".$vals[$i];
}
}
$creport->ExportOptions->DiskFileName=$output_pdf;
$creport->ExportOptions->FormatType=31;//constant for PDF export
$creport->ExportOptions->DestinationType=1;
$creport->Export(false);
if(file_exists($my_pdf)){
$pdf=file_get_contents($my_pdf);
if(strlen($pdf)!=filesize($my_pdf))
return "Error: filesize=".filesize($my_pdf)." strlen=".strlen($pdf);
header("Pragma: ");
header("Cache-Control: ");
header("Content-type: application/pdf");
header("Content-Disposition: attachment;filename=".$reportName.".pdf"); // For IE
echo("lll " . $pdf);
exit();
}else {
echo "failed neh";
//return "Failed to export";
}
}
catch(Exception $e)
{
echo 'Message: ' .$e->getMessage();
}
?>
</form>
</body>
</html>
The Exception is :
Message: Source: Crystal Reports ActiveX Designer
Description: Invalid TLV record. [/B]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|