I'm having issues with reporting a Crystal Reports file to PDF format. I've looked at all the other questions here regarding the issue but none of them seem to solve mine.
Here is my code:
Public Sub ExportReportToPDF(ReportObject As CRAXDRT.Report, ByVal filename As String, ByVal ReportTitle As String)
Dim objExportOptions As CRAXDRT.ExportOptions
ReportObject.ReportTitle = ReportTitle
With ReportObject
.EnableParameterPrompting = False
.MorePrintEngineErrorMessages = True
End With
Set objExportOptions = ReportObject.ExportOptions
With objExportOptions
.DestinationType = crEDTDiskFile
.DiskFileName = filename
'.FormatType = crEFTExcel80Tabular
'.FormatType = crEFTCommaSeparatedValues
'.FormatType = crEFTExcel80
'.FormatType = crEFTHTML32Standard
'.FormatType = crEFTHTML40
.FormatType = crEFTPortableDocFormat
'.FormatType = crEFTRichText
'.FormatType = crEFTText
'.FormatType = crEFTWordForWindows
End With
ReportObject.Export False
End Sub
Now, I've left the other options besides PDF in there just to show them, they're all commented out obviously, but if I try any of the other formats, it exports just fine. The only format that doesn't export is PDF. It gives me the error:
Run-time error '-2147190908 (80047784)':
Failed to Export the Report.
When I click Debug it highlights on the ReportObject.Export False line.
On another note, if I make it so the user chooses the options, I can select PDF and it still gives me the same error. Thanks for the help.
(Thanks to AVD for the coding found here How to Export to a PDF file in Crystal Report?).
EDIT: After going through Phillipe's responses, I was stepping through my code and noticed that after it assigned crEFTPortableDocFormat to FormatType, it auto assigns "UXFPDF.DLL" to FormatDllName. Maybe this is my problem, does anyone know how to fix this? I tried just renaming crxf_pdf.dll and also u2fpdf.dll (the one that was for 8.0 which I originally had) but that didn't work.
EDIT: Another find is that when I enable the Export Option in CRViewer91 (which shows the report correctly) and I try and export this to a pdf via this method, it does not error. However, it saves a file that is corrupted pretty much and cannot be opened.
EDIT: More research. The CRViewer91 doesn't appear to be able to export any format successfully. RTF and TXT return a blank document, RPT errors when trying to open.
EDIT: I think part of my problem may be that I've been using the 8.0 CRAXRT.DLL when what I actually need is the 9.0 one. I've found the one for 9.0, now how do I make it use this instead of the old one?
Best Answer
I guess that 'filename' value does not work, either because the folder does not exist / the file name is not valid, or because you do not have the corresponding rights to create a file under this folder.
Could you try the code with some basic parameter like 'filename = "c:\test.pdf"'?
My last guess: the possibility to export to pdf format needs a specific dll file under the crystal folder (does not need to be registered but needs to be here). Do you have the crxf_pdf.dll file ?
EDIT:
My last question: are you able to expor tto PDF from the Crystal GUI?
Here is a list of the crystal report files that must be distributed with a VB app, if of any help: export capabilities seem to be linked to the crxf_*.dll files