我有一个类似的问题。在我的报告中有一些文字和图像。我读过 Crystal Report 首先将 JPG、PNG 等图像转换为 BMP,然后显示报告。并且将其他图像类型转换为 BMP 会消耗大量内存。首先,我尝试将数据库中的 JPG 图像转换为 BMP 图像,但随后我的数据库变得越来越大。最后我找到了解决方案(感谢这个答案)。
我没有尝试将所有页面导出为 PDF 文件,而是拆分文件,压缩它们并下载 zip 文件:
Dim exportOpts As ExportOptions = New ExportOptions()
Dim pdfRtfWordOpts As PdfRtfWordFormatOptions = ExportOptions.CreatePdfRtfWordFormatOptions()
Dim destinationOpts As DiskFileDestinationOptions = ExportOptions.CreateDiskFileDestinationOptions()
Dim intPageCount As Integer = crReportDocument.FormatEngine.GetLastPageNumber(New CrystalDecisions.Shared.ReportPageRequestContext)
Dim pagecount As Integer
pagecount = Int(intPageCount / 100) + 1
Dim sonsayfa As Integer
Dim ilksayfa As Integer
Dim Anadosyaadi As String
Dim foldername As String
Dim foldernameMap As String
Anadosyaadi = Now.ToString("yyyy-MM-dd-hh-mm-ss")
foldername = "C:\inetpub\wwwroot\" + Anadosyaadi
foldernameMap = "./" + Anadosyaadi
If Not Directory.Exists(foldername) Then
Directory.CreateDirectory(foldername)
End If
For li_count As Integer = 1 To pagecount
ilksayfa = (li_count - 1) * 100 + 1
pdfRtfWordOpts.FirstPageNumber = ilksayfa
sonsayfa = li_count * 100
If sonsayfa > intPageCount Then sonsayfa = intPageCount
pdfRtfWordOpts.LastPageNumber = sonsayfa
pdfRtfWordOpts.UsePageRange = True
exportOpts.ExportFormatOptions = pdfRtfWordOpts
exportOpts.ExportFormatType = ExportFormatType.PortableDocFormat
destinationOpts.DiskFileName = foldername + "\" + li_count.ToString + ".pdf"
exportOpts.ExportDestinationOptions = destinationOpts
exportOpts.ExportDestinationType = ExportDestinationType.DiskFile
crReportDocument.Export(exportOpts)
Next
Using zip As ZipFile = New ZipFile
zip.AddDirectory(foldername)
zip.Save(foldername + "\" + Anadosyaadi + ".zip")
End Using
Response.Redirect(foldernameMap + "/" + Anadosyaadi + ".zip")
PS1:我使用 Ionic.Zip 压缩文件。你应该添加
Imports Ionic.Zip
在您的来源之上。
PS2:重启服务器后,什么都不做,就可以得到从1到500页的500页PDF。这个时候,我想,Crystal Reports占用了一些内存。然后,如果我想获得第二个 500 页(我的意思是从页码 501 到 1000),我会看到内存已满错误。然后我可以得到 300 页(从 501 到 800)。然后是另一个内存满的问题,我可以从 801 到 900,等等。这就是为什么我更喜欢拆分 100 页。也许您可以将其更改为另一个数字。