【发布时间】:2010-04-01 15:43:00
【问题描述】:
我有几个 pdf 文件的二进制文件存储在字节数组的集合中。
我的目标是使用 abcpdf 将它们连接成单个 .pdf 文件,然后将该新创建的文件流式传输到 ASP.Net 网站页面上的 Response 对象。
一直是这样的:
开始循环 ...
'Create a new Doc
Dim doc As Doc = New Doc
'Read the binary of the current PDF
doc.Read(bytes)
'Append to the master merged PDF doc
_mergedPDFDoc.Append(Doc)
结束循环
这在 95% 的时间里都运行良好。但是,时不时地,创建一个新的 Doc 对象会引发 System.ExecutionEngineException 并使 CLR 崩溃。它似乎与大量的 pdf 无关(有时会发生只有 2 个),或者与大尺寸的 pdf 无关。它似乎几乎完全随机。
这是 abcpdf 中的一个已知错误,在 Item 6.24 处描述(不是很好)。我遇到了a helpful SO post,它建议对 abcpdf Doc 对象使用 Using 块。
所以现在我正在这样做:
Using doc As New Doc
'Read the binary of the current PDF
doc.Read(bytes)
'Append to the master merged PDF doc
_mergedPDFDoc.Append(doc)
End Using
而且我还没有看到问题再次出现,并且一直在尽可能地尝试测试版本。
有没有人对这个错误有过类似的经历?这解决了吗?
【问题讨论】:
-
FWIW 我不知道如何修复这个错误,或者
using是否会继续阻止它,但我使用 iTextSharp PDF 库做几乎相同的事情并且没有任何问题(我正在添加 100 多个文档)