Thursday, March 16, 2006

PHP <=> Crystal Reports 11

Consegui.Vou até postar em inglês pois isso pode ser de valia para alguem por aí.

I almost killed myself (of frustration and boreness) while trying to export to PDF a Crystal Report (v11). The thing is, I'm too used to the open-source community, so it's easy to ask google any question and get an answer in less than15 minutes.

It's not so in the otherside. Tech information about Crystal Reports is hard (if not impossible) to find in the Web, the only thing avaliable is the help file from original product, hard to buy. And it's also badly arranged, so my tip is: Search for "Report Viewer Object", "Report Viewer Methods". It's not easy to get from on to another using only the mouse (charmap is not included).

So, here's a sample:

$ObjectFactory= New COM("CrystalReports11.ObjectFactory.1");
$crapp = $ObjectFactory->CreateObject("CrystalDesignRunTime.Application");
$creport = $crapp->OpenReport($my_report, 1);

$creport->ExportOptions->DestinationType=1; // Export to File
$creport->ExportOptions->FormatType=31; // Type: PDF

Not bad, isn't? This piece of s^Hcode is not lying around here. I had to learn something about VB and ASPX in order to produce it, learning-by-error.

The "new COM" creates a new object of class COM, which, according to, permits access to windows OLE applications or whatever (sic). Obviously, it's not avaliable to PHP under Linux, and in the Windows version it's built-in. Not Bad. It works for Word, Excel, and many applications, but you can't simply print_r( new COM("Word.Application") ); to seek for methods, as I usually do. You have to rely on some documentation, and there it comes...

Well, I'm now posting it at Hope they don't erase it, as they did with my last comment about CReports. Maybe somebody at doesn't like CR, as do I =)

Comments: Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?