我想在 Crystal Report 中从 ASP.Net 制作报告。我想要,当用户单击打印时,它应该只显示“保存”、“打开”、“另存为”的浏览器对话框,并且应该保存 PDF,或者应该出现 Crystal 报表打印预览,然后我不想先在查看器中显示报表单击按钮获取打印或 PDF,我想简单地单击 asp 按钮,我了解所有参数并知道如何制作报告,我的问题只是不显示查看器并从表单中的 asp 按钮获取报告PDF 或打印预览对话框进行打印。我已经使用了.Net for Crystal Report的Export方法,但是不起作用。
最佳答案
您可以使用 Crystal Report 和一段代码生成 PDF...
第一:根据您的要求生成 Crystal Report。
第二:使用以下代码生成 PDF:
将以下 namespace 放置在代码页顶部
Imports CrystalDecisions.CrystalReports.Engine Imports CrystalDecisions.Shared
变量声明
Dim CrReport As New CrystalReport1() // Report Name Dim CrExportOptions As ExportOptions Dim CrDiskFileDestinationOptions As New DiskFileDestinationOptions() Dim CrFormatTypeOptions as New PdfRtfWordFormatOptions()
设置目标路径和文件名
CrDiskFileDestinationOptions.DiskFileName = "c:\RichText.pdf"
指定页面范围(可选)
crFormatTypeOptions.FirstPageNumber = 1 // Start Page in the Report crFormatTypeOptions.LastPageNumber = 3 // End Page in the Report crFormatTypeOptions.UsePageRange = True
设置导出选项
CrExportOptions = crReport.ExportOptions With CrExportOptions // Set the destination to a disk file .ExportDestinationType = ExportDestinationType.DiskFile // Set the format to PDF .ExportFormatType = ExportFormatType.PortableDocFormat // Set the destination options to DiskFileDestinationOptions object .DestinationOptions = CrDiskFileDestinationOptions .FormatOptions = crFormatTypeOptions End With
捕获导出时发生的任何错误
Try // Export the report CrReport.Export() Catch err As Exception MessageBox.Show(err.ToString()) End Try
就是这样......现在您已准备好创建报告的 PDF。
关于asp.net - Crystal Report直接保存为PDF,而不是查看,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6210660/