Fun with PHP, PDFs, and Crystal Reports!

Vogel515

Senior member
Jun 17, 2005
249
0
0
Hello - so in recent weeks I have been experimenting quite a bit with PHP & SQL.

I am looking for guidance in how I might:

a) automatically fun a crystal report using php
b) print that crystal report to a pdf
c) make that pdf accessible to a user

Thanks in advance!

Writing these reports straight to a pdf is out of the question - too large, too much formatting

If I could print an html view to pdf, I might be able to manage that...
 

Vogel515

Senior member
Jun 17, 2005
249
0
0
Hey KLin,

I have acrobat professional and I know how to create pdf's using php, the issue I'm having is the ability to automatically run a crystal report, and then have that print to a pdf to make it accessible to the user.

Thanks for your help!
 

sourceninja

Diamond Member
Mar 8, 2005
8,805
65
91
Depending on the report you could design the report and then place fields in the report using the fpdf library for php. Otherwise running a crystal report automatically without crystal reports server or buisness objects enterprise server is not something I know how to do.

 

Vogel515

Senior member
Jun 17, 2005
249
0
0
Hey sourceninja - thanks for the help... I think I may end up sticking with HTML, produce the reports manually into a huge web page with CSS page breaks, maybe that'll do it.
 

sourceninja

Diamond Member
Mar 8, 2005
8,805
65
91
I've never had much luck with css page breaks being consistant. Which is why I use the pdf librarys for php. I mentioned fpdf, but I really ment FPDI. What that lets you do is easily build a template pdf file, then load it and add to it via php. So I layout say a empty student bill, load it with fpdi and add the bill text as needed.
 

Vogel515

Senior member
Jun 17, 2005
249
0
0
The problem is I can't just use a template because the number of data rows will vary...

for example, one customer might have 15 orders while the next might have 50....
 

sourceninja

Diamond Member
Mar 8, 2005
8,805
65
91
We have the same thing, some of my forms have a front page and a 'repeating page' that. So the first 15 line items on the main page, then I use the repeating page template for the next 25 (and in theory if a student ever had more line items then that we would repeat that same page).

On other items, such as say a transcript, we use the same template over and over for each page, but we add the word ** continued ** on the top. This way each page has all the header information someone might want as well as the detail information. Then we usually add a canned pdf page on the end that includes our privacy statement.
 

Vogel515

Senior member
Jun 17, 2005
249
0
0
Yea, I'm not so sure it'll work for what I'm doing... it's actually effort reporting for the government.

I need to show what % of a person's salary is going to a given project (ranges from 1-6 projects typically) then I have a header / footer and it all needs to fit on one page.
 

Hmongkeysauce

Senior member
Jun 8, 2005
360
0
76
I've done a similar thing for my company, but in ASP.NET instead. I tried PHP first, but found that ASP.NET(C#) is much better with Crystal Reports. Is that an option?
 

sourceninja

Diamond Member
Mar 8, 2005
8,805
65
91
OHHH you are using php on windows. Well you can use the COM object to access the crystal reports com object similar to asp.net.

Some quick googling found.

$crapp = new COM ("CrystalRuntime.Application") or die ("Error on
load");
$creport = $crapp->OpenReport("c:/test.rpt", 1);
$creport->ExportOptions->DiskFileName="c:/test.rtf";
$creport->ExportOptions->DestinationType=1; // Export to File
$creport->ExportOptions->FormatType=4; // Type: RTF
$creport->DiscardSavedData();
$creport->Export(false);
etc....

This is php5 of course.

And you can see all the possible methods exposed with a script similar to
$crapp = new COM ("CrystalRuntime.Application")
or die ("Error on load");
echo "<p>Enumerating CrystalRuntime.Application object:</p>";
$crapp->Reset();
while ($e = $crapp->Next()) {
echo "<p>$e</p>";
}

I grabbed this off a quick google.

Sorry, I'm used to people meaning linux when they say php.
 

Vogel515

Senior member
Jun 17, 2005
249
0
0
I should have specified about running windows...


This is great, I'll have to fiddle with it a bit!

Thank you very much!

Now for my next issue... I've got a windows laptop, I'm running apache / mysql locally (xampp), I'm also on my work network and would like to test what I'm doing against the production server (SQL) - when specifying my host, can I use local host? is this going to cause a conflict choosing the DB?

Sorry this is my first attempt at this and I have no clue how it works.
 

sourceninja

Diamond Member
Mar 8, 2005
8,805
65
91
Localhost will connect you to the database running on your laptop. If you want to connect to your works sql server you are going to need to specify it's dns name or ip address. Running mysql on your work laptop should not effect any other database servers on your network.