简体   繁体   中英

VB 6.0 Crystal Reports Export to PDF

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?

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

CRAnalyzer.dll
craxdrt.dll
crdb_ado.dll
crdeploy.reg
crheapalloc.dll
crqe.dll
crtowords_en.dll
crtslv.dll
crviewer.dll
crxf_html.dll
crxf_pdf.dll
crxf_rtf.dll
crxf_wordw.dll
crxf_xls.dll
cxlibw-1-6.dll
dbghelp.dll
exlate32.dll
ExportModeller.dll
GDIPLUS.DLL
Implode.dll
keycode.dll
msvcrt.dll
pageObjectModel.dll
querybuilder.dll
ReportRenderer.dll
riched20.dll
sscdlg.dll
sscsdk80.dll
u252000.dll
u25dts.dll
u25samp1.dll
u2dapp.dll
u2ddisk.dll
u2dmapi.dll
u2dpost.dll
u2fcr.dll
u2frdef.dll
u2frec.dll
u2fsepv.dll
u2ftext.dll
u2fxml.dll
u2l2000.dll
u2lcom.dll
u2ldts.dll
u2lexch.dll
u2lfinra.dll
ufmanager.dll
usp10.dll
webReporting.dll

I'm not exactly sure what was causing all the errors, however, I've fixed it via basically starting a new project from scratch and incorporating only the necessary references and components. I know one problem I had (which caused a TLV error) was that the CRAXDRT.dll for CR9 was in the Windows\\system32 directory, and even though it was referencing that .dll, it needed to reference it from the Program Files\\Common Files\\CrystalDecision... directory where all the other .dlls for CR9 are located.

There was also a minor code change that needed to be done, here is the finalized code that works for exporting mine to PDF.

Public Sub ExportReportToPDF(ReportObject As CRAXDRT.Report, ByVal filename As String, ByVal ReportTitle As String)

    Dim FormatDLLName As String

    ReportObject.ReportTitle = ReportTitle

    With ReportObject
        .EnableParameterPrompting = False
        .MorePrintEngineErrorMessages = True
    End With

    With ReportObject.ExportOptions
        .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

I left the commented out FormatTypes in there for anyone else who finds this code useful. Phillipe, if you would like to "answer" this somehow like this, I would love to give you some rep for all of your help that you provided however. I don't have enough rep to just upvote your stuff so.

Thanks for all your help either way.

Dan

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM