【发布时间】:2012-12-07 18:24:01
【问题描述】:
在我的 asp.net/c# 项目中,我使用 iTextsharp dll 从许多 pdf 文档中读取文本,但有时我会收到此错误
System.Web.HttpException:请求超时。
但是执行它的代码是:
public static bool does_pdf_have_keyword(string keyword, string pdf_src)
{
try
{
PdfReader pdfReader = new PdfReader(pdf_src);
string currentText;
int count = pdfReader.NumberOfPages;
for (int page = 1; page <= count; page++)
{
ITextExtractionStrategy strategy = new SimpleTextExtractionStrategy();
currentText = PdfTextExtractor.GetTextFromPage(pdfReader, page, strategy);
if (currentText.IndexOf(keyword, StringComparison.OrdinalIgnoreCase) != -1) return true;
}
pdfReader.Close();
return false;
}
catch
{
return false;
}
}
那么为什么页面在尝试捕获时会进入未处理的异常,而捕获应该捕获所有内容?
【问题讨论】:
-
你是怎么运行这个的?在 Visual Studio 中?
-
请发布堆栈跟踪
-
不,它是一个在 sharepoint 2010 中运行的 web 部件(所以在服务器端),如果页面进入未处理的错误状态,我如何获得它的堆栈跟踪?如果我能够捕捉到错误,我可以获得堆栈跟踪。
-
我怀疑这甚至不是引发该异常的代码部分,因为 PdfReader(string filename) 从文件而不是 url 读取。我的猜测是这个操作耗时太长,http请求超时。
-
@christian,不,它也可以从 pdf 的路径读取,因为它大部分时间都可以工作,但有时我会收到请求超时的未处理错误。
标签: c# asp.net itextsharp httprequest