Create report in PDF format from Crystal Report via PHP and COM : COM (Windows) : COM and .Net (Windows) PHP Source Code


PHP Source Code » COM and .Net (Windows) » COM (Windows) »

 

Create report in PDF format from Crystal Report via PHP and COM


Requirements : PHP 5.1.6, MSSQL2005 and Crystal Report
Make sure that the line $ObjectFactory= new COM("CrystalReports115.ObjectFactory.1") in examples below is correct for your version of Crystal Reports as shown in the table below.

Version

Object

7

Crystal.CRPE.Application

8.0

CrystalRuntime.Application
or
CrystalRuntime.Application.8

8.5

CrystalRuntime.Application
or
CrystalRuntime.Application.8.5

9 (RDC)

CrystalRuntime.Application.9

9 (RAS) CrystalReports.ObjectFactory.2
10 (RDC) CrystalRuntime.Application.10
10  (CEE) CrystalReports10.ObjectFactory.1
XI (RDC) CrystalRuntime.Application.11
XI (RAS) CrystalReports11.ObjectFactory.1
XI R2 (RDC) CrystalRuntime.Application.115
<?php

//- Variables - for your RPT and PDF
echo "Print Report Test";
$my_report "C:\\TestFolder\\SubFolder1\\MyWebReport.rpt"//
rpt source file
$my_pdf 
"C:\\TestFolder\\SubFolder1\\MyWebReport.pdf"// RPT export to pdf file
//-Create new COM object-depends on your Crystal Report version
$ObjectFactory= new COM("CrystalReports115.ObjectFactory.1") or die ("Error on load"); // call COM port
$crapp $ObjectFactory-> CreateObject("CrystalDesignRunTime.Application"); // create an instance for Crystal
$creport $crapp->OpenReport($my_report1); // call rpt report

// to refresh data before

//- Set database logon info - must have
$creport->Database->Tables(1)->SetLogOnInfo("servername""DBname""user""password");

//- field prompt or else report will hang - to get through
$creport->EnableParameterPrompting 0;

//- DiscardSavedData - to refresh then read records
$creport->DiscardSavedData;
$creport->ReadRecords();

   
//export to PDF process
$creport->ExportOptions->DiskFileName=$my_pdf//export to pdf
$creport->ExportOptions->PDFExportAllPages=true;
$creport->ExportOptions->DestinationType=1// export to file
$creport->ExportOptions->FormatType=31// PDF type
$creport->Export(false);

//------ Release the variables ------
$creport null;
$crapp null;
$ObjectFactory null;

//------And Now -> Embed the report in the webpage ------
print "<embed src=\"C:\\TestFolder\\SubFolder1\\MyWebReport.pdf\" width=\"100%\" height=\"100%\">"

   
   
?>


HTML code for linking to this page:

Follow Navioo On Twitter

PHP Source Code

 Navioo COM and .Net (Windows)
» COM (Windows)