简体   繁体   English

VB 6.0 Crystal Reports导出为PDF

[英]VB 6.0 Crystal Reports Export to PDF

I'm having issues with reporting a Crystal Reports file to PDF format. 我在将Crystal Reports文件报告为PDF格式时遇到问题。 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. 现在,除了PDF之外我还留下了其他选项只是为了展示它们,它们都被明确地注释掉了,但是如果我尝试任何其他格式,它输出就好了。 The only format that doesn't export is PDF. 唯一不导出的格式是PDF。 It gives me the error: 它给了我错误:

Run-time error '-2147190908 (80047784)': Failed to Export the Report. 运行时错误'-2147190908(80047784)':导出报告失败。

When I click Debug it highlights on the ReportObject.Export False line. 当我单击Debug时,它会在ReportObject.Export False行上突出显示。

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. 另一方面,如果我这样做,用户选择了选项,我可以选择PDF,它仍然给我同样的错误。 Thanks for the help. 谢谢您的帮助。

(Thanks to AVD for the coding found here How to Export to a PDF file in Crystal Report? ). (感谢AVD的编码, 如何在Crystal Report中导出为PDF文件? )。

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. 编辑:在完成Phillipe的回复之后,我正在逐步完成我的代码并注意到在将crEFTPortableDocFormat分配给FormatType之后,它会自动将“UXFPDF.DLL”分配给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. 我试过重命名crxf_pdf.dll和u2fpdf.dll(我原来拥有的8.0版),但是没有用。

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. 编辑:另一个发现是,当我在CRViewer91中启用导出选项(正确显示报告)并尝试通过此方法将其导出为pdf时,它不会出错。 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. CRViewer91似乎无法成功导出任何格式。 RTF and TXT return a blank document, RPT errors when trying to open. RTF和TXT返回空白文档,尝试打开时出现RPT错误。

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. 编辑:我认为我的问题的一部分可能是我一直在使用8.0 CRAXRT.DLL,而我实际需要的是9.0。 I've found the one for 9.0, now how do I make it use this instead of the old one? 我找到了一个9.0,现在如何使用它而不是旧的?

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. 我猜'filename'值不起作用,因为文件夹不存在/文件名无效,或者因为您没有相应的权限来在此文件夹下创建文件。

Could you try the code with some basic parameter like 'filename = "c:\\test.pdf"'? 你能尝试一些基本参数的代码,比如'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). 我的最后一个猜测:导出为pdf格式的可能性需要一个特定的dll文件在crystal文件夹下(不需要注册,但需要在这里)。 Do you have the crxf_pdf.dll file ? 你有crxf_pdf.dll文件吗?

EDIT: 编辑:

My last question: are you able to expor tto PDF from the Crystal GUI? 我的上一个问题:你能从Crystal GUI中发布PDF吗?

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 以下是必须与VB应用程序一起分发的水晶报表文件列表,如果有任何帮助:导出功能似乎链接到crxf _ * .dll文件

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. 我知道我遇到的一个问题(导致TLV错误)是CR9的CRAXDRT.dll在Windows \\ system32目录中,即使它引用了.dll,它也需要从Program Files \\ Common引用它Files \\ CrystalDecision ...目录,其中CR9的所有其他.dll都位于此目录中。

There was also a minor code change that needed to be done, here is the finalized code that works for exporting mine to PDF. 还需要进行一些次要的代码更改,这里是最终的代码,用于将我的导出为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. 我把那里注释掉的FormatTypes留给了那些发现这段代码有用的人。 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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