我有几个 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中描述(不是很好)。我遇到了一篇有用的 SO 帖子,该帖子建议对 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
而且我还没有看到问题再次发生,并且一直在尽可能地尝试测试版本。
有没有人对这个错误有过类似的经历?这解决了吗?