3

我们有一个 asp.net 3.5 应用程序,它允许用户生成许多图表并通过 pdf 导出它们。这适用于较小的 pdf(少于 100 页),但是当我们处理较大的 pdf 时,会出现随机错误。我们看到的一些错误是:

--System.OutOfMemoryException
-- 无法呈现 HTML 字符串。无法从 html 字符串获取图像。尝试设置 LoadHtmlConcurrencyLevel = 1..
--克隆错误。内存不足..
-- 等待转换完成超时。
--System.OutOfMemoryException:内存不足。在 System.Drawing.Image.FromStream(流流,布尔 useEmbeddedColorManagement,布尔 validateImageData) 在 System.Drawing.Image.FromStream(流流)

如果我多次运行大型报告,我通常会得到不同的异常。有时我可以让 IIS 崩溃,我必须执行 iisreset 才能恢复应用程序。

这是我们运行的代码。我们使用图表(png 图像)创建 PDF 文档,然后将其导出到字节数组并放入内存流中。我们将内存流传递给旋转一些图像等的函数,然后调用 doc.save 方法将其导出。

Dim mainPageBytes() As Byte = PDF.GetBytes
Dim stream As New System.IO.MemoryStream(mainPageBytes)
Dim existingDoc As New PDFCreator.Document(stream)
Dim doc As PDFCreator.Document = GetDocument(mainPageBytes,    GetChartingPageNumbers(PDF.ConversionSummary), pageOrientation, user, existingDoc)
doc.Save(response, True, Me.DocumentName)
4

2 回答 2

3

IIS has limits on the scripts that run on it, both for memory and runtime. Presumably your script is going over the runtime and/or memory limits. These can be set in the IIS configuration settings, but they're generally there for a reason (to prevent a single script from eating up all the memory on the server, or to prevent a script from running forever in an infinite loop which you would have no way of exiting short of restarting IIS.)

Turn on debugging (which disables those limits) and determine how much memory your scripts are actually using when they crash by outputing queryObj("PeakWorkingSetSize") to a log file.

于 2010-01-14T04:30:53.307 回答
0

您是否按照产品文档中的建议在 64 位进程中运行转换器?您可以在我们的在线文档中查看部署要求。在 32 位模式下,.NET 的可用内存非常有限。在 IIS 中,您必须确保 32 位应用程序标志为假。

此外,为了在转换包含大量图像的 HTML 页面时减少内存使用量,您可以将 ImagesScalingEnabled 属性设置为 false。您可以在设置图像缩放和 JPEG 压缩级别演示中找到此功能的完整示例代码。

于 2014-08-08T06:48:24.880 回答