|
-
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]
-
Dec 24th, 2009, 06:04 PM
#2
Re: Crystal Reports issue with PHP
Hi,
Could you please wrap your code in [php] [ /php] tags to make it easier for people to read your code. Also, this thread belongs in the php forum, so I will request it moved to the correct location.
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Dec 27th, 2009, 12:55 PM
#3
Re: Crystal Reports issue with PHP
Thread moved to 'PHP forum
-
Dec 27th, 2009, 01:29 PM
#4
Re: Crystal Reports issue with PHP
Have you tried Google? A number of people appear to have this problem - the issue may not be in your PHP.
Otherwise, I'd check your paths for the variables defined on the first two lines, and I don't see the variable $output_pdf defined before you use it.
-
Dec 28th, 2009, 07:33 AM
#5
Thread Starter
New Member
Re: Crystal Reports issue with PHP
Hi All,
Actually the exception is from the report open section itself. I removed other export options from the code. Now the the code is as below. The crystal report has no input parameters ,the query is already written in the report.
Still i get the same error. What could be the exception saying. How to display a simple report in 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);
}
catch(Exception $e)
{
echo 'Message: ' .$e->getMessage();
}
-
Dec 29th, 2009, 11:40 AM
#6
Re: Crystal Reports issue with PHP
I don't think anyone here is a Crystal Reports person. you may want to look at Google, like Samba suggested, as it doesn't seem too common to be doing this with PHP. this is, of course, assuming you haven't Googled anything already.
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
|