0% found this document useful (0 votes)
128 views2 pages

Cetak Crystal Report Dengan PHP

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
128 views2 pages

Cetak Crystal Report Dengan PHP

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Example to print Crystal Report in php | Ali Presence https://asabali.wordpress.com/2013/04/23/example-to-print-crystal-report...

Ali Presence
APRIL 23, 2013 · 12:21 PM

Example to print Crystal Report in php


I couldn’t find an example anywhere on what I was trying to do. After taking bits from everyone I ended up with
something that worked.

Im using Crystal Reports 10, MS SQL Server 2005, Apache2, and PHP5.

My report uses an SQL Store Procedure and passes some parameter to get the report data, so our PHP must set
the database logon info and pass the parameters.

Below is the solution I came up with:

<?php

//—— Variables ——
$my_report = “C:\\Apache2\htdocs\\test\\MyReport.rpt”; //This must be the full path to the file
$my_pdf = “C:\\Apache2\htdocs\\test\\MyReport.pdf”;

//—— Create a new COM Object of Crytal Reports 10 ——


$ObjectFactory= new COM(“CrystalReports10.ObjectFactory.1″);

//—— Create a instance of library Application ——-


$crapp = $ObjectFactory->CreateObject(“CrystalDesignRunTime.Application.10″);

//—— Open your rpt file ——


$creport = $crapp->OpenReport($my_report, 1);

//—— Set database logon info ——


$creport->Database->Tables(1)->SetLogOnInfo(“MYSERVER”, “Database”, “user”, “password”);

//—— Suppress the Parameter field prompt or else report will hang ——
$creport->EnableParameterPrompting = 0;

//—— DiscardSavedData make a Refresh in your data ——-


$creport->DiscardSavedData;
$creport->ReadRecords();

//—— Pass formula fields ——–


$creport->FormulaFields->Item(1)->Text = (“‘My Report Title'”);
$creport->ParameterFields(1)->AddCurrentValue (“FirstParameter”);
$creport->ParameterFields(2)->AddCurrentValue (2000);

1 of 3 30/03/2015 11:18
Example to print Crystal Report in php | Ali Presence https://asabali.wordpress.com/2013/04/23/example-to-print-crystal-report...

//—— Export to PDF ——-


$creport->ExportOptions->DiskFileName=$my_pdf;
$creport->ExportOptions->FormatType=31;
$creport->ExportOptions->DestinationType=1;
$creport->Export(false);

//—— Release the variables ——


$creport = null;
$crapp = null;
$ObjectFactory = null;

//—— Embed the report in the webpage ——


print “”

?>

Obviously there’s plenty of room for refinement in there, but it works and should get you going on the right track.
I also found that during testing, the script was hanging before supressing the parameter prompt. Once this had
happened, some exports that had been working earlier stopped completely and wouldn’t work again untill I
restarted Apache.

Share this:

Be the first to like this.

Related

Crystal Report Sample in


ASP.net 2008

How to Create an Image in


PHP OR CAPTCHA images
in PHP

PHP and .NET - Image


Rotation Example using C#
and PHP

One response to “Example to print Crystal


Follow “Ali
2 of 3 30/03/2015 11:18

You might also like