Results 1 to 6 of 6

Thread: Crystal Reports issue with PHP

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2009
    Posts
    2

    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]

  2. #2
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    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

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Crystal Reports issue with PHP

    Thread moved to 'PHP forum

  4. #4
    Frenzied Member
    Join Date
    Apr 2009
    Location
    CA, USA
    Posts
    1,516

    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.

  5. #5

    Thread Starter
    New Member
    Join Date
    Dec 2009
    Posts
    2

    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();
    }

  6. #6
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    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
  •  



Click Here to Expand Forum to Full Width