Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using ASP to export Crystal Report to PDF format

Status
Not open for further replies.

exotech

Programmer
Jul 17, 2001
4
CA
Hi all,
We purposely bought Crystal Reports Developer v. 8.5 so we could export our reports to PDF format.
I've been trying to get the sample reports to export to PDF, with no luck. Crystal Tech support has not been very helpful, either.
I ran their sample report from aspxmps85.exe (SimpleReportExport.asp) and it appeared to work, redirecting to the sample .doc file. However, I noticed that when I deleted that .doc file, I would get a file not found error (because the report wasn't exporting!). I tested to see whether the report was actually retrieving anything in the asp page by inserting the report viewer include, and it displayed fine. So, for some reason even their code is not exporting.
In their sample file, SimpleReportExport, I have modified their export code to the following, in order to export to PDF:

ExportFileName = "ExportedReport.pdf"

Path = Request.ServerVariables("PATH_TRANSLATED")
While (Right(Path, 1) <> &quot;\&quot; And Len(Path) <> 0)
iLen = Len(Path) - 1
Path = Left(Path, iLen)
Wend
'The While/Wend loop is used to determine the physical location
'of the SimpleReportExport.asp so that we can save the
'ExportedReport.doc in the same location.

ExportDirectory = Path
ExportType = &quot;31&quot;

CrystalExportOptions.DiskFileName = ExportDirectory & ExportFileName

'This line of code specifies the physical location and file name to give
'the export result.

CrystalExportOptions.PDFExportAllPages True

CrystalExportOptions.UseReportNumberFormat True

CrystalExportOptions.UseReportDateFormat True

CrystalExportOptions.FormatType = CInt(ExportType)
'This line of code specifies the export format (in this case MS Word).

CrystalExportOptions.FormatDLLName &quot;crxf_pdf.dll&quot;

CrystalExportOptions.DestinationType = CInt(1)
'This line of code specifies that the export destination is to be disk.

Session(&quot;oRpt&quot;).Export False
'This line of code turns of any prompting when exporting.

Response.Redirect (&quot;ExportedReport.pdf&quot;)

Please, can anyone help me with this problem, it's becoming very annoying! :(

 
You could put some ON ERROR code on the page and see if the thing is bombing out before exporting.

And, of course, whatever username is running the web page (often &quot;Anonymous&quot;) has to have write access to the directory where the PDF file is going to be saved.

And there's this KB article, you never know:


I didn't know that you could do a Response.Redirect to a file (instead of a URL). But I guess it must work, or it wouldn't be in the example. Brian J. Alves
Email: brian.alves@worldnet.att.net
VB / Crystal / SQLServer
 
Brian,
Thanks for your tip. I actually figured it out earlier today: the sample page had a couple of include files in it, and I noticed they both had &quot;on error resume next&quot; lines in those files! As soon as I commented them out, I got a different error: &quot;Access Denied&quot;. This led me to the realization that the specific folder that the sample was in needed to have the rights reset. (Funny, that's the first thing I checked). As soon as I did that, it exported (to all formats)! Now the conversion to PDF works, only it truncates part of the data (it's from a MS SQL Server text field). For some reason, the Crystal Report Viewer displays the report correctly (without anything missing), but on export to PDF the data starting on pg 2 prints for 2 lines, and the rest of the page is blank. The report continues fine on pg 3, except the remainder of page 2 never gets printed. Any ideas?
Any help would be appreciated.
Natalie
 
Actually ON ERROR RESUME NEXT is the only choice you have in VBscript (unlike ON ERROR GOTO in Visual Basic). You do have the Err object, so you could have left the ON ERROR RESUME NEXT statements in there and periodically done an

IF Err THEN

END IF

With the PDF export, maybe it's a big text field that doesn't fit or a Keep Together option on a section? Brian J. Alves
Email: brian.alves@worldnet.att.net
VB / Crystal / SQLServer
 
Well, it wasn't my code; but I wouldn't have put it in any sample code to send to customers: if something isn't working, using on error resume next makes debugging difficult!

As for the text field not fitting, I don't know why it's doing what it is: I've tried setting it to Keep Together, but when I do that, it displays a blank page at the beginning, then continues on the second page. This is not acceptable for our purposes. I saw a tip in the Crystal Reports Knowledge Base about setting the margin to Left and changing the font to Times New Roman, but we can't do that, because the text we're displaying is preformatted, and portions of it are in columns, so we have to use a font like Courier to display it correctly! I modified my report to do what their tip suggested, and the PDF version still has that mostly blank second page.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top