我正在使用abcpdf10来读取pdf文件。每当我的代码遇到空的pdf文件(0kb)时,document.Read(pdfPath)就会抛出异常。
using (var document = new Doc())
{
document.Read(pdfPath);
}如果我的代码遇到空文件,我需要忽略并继续。我不知道该怎么做。使用C#和ABCPDF10 (websupergoo)
发布于 2018-02-28 00:33:49
您可以使用try-catch块来捕获异常:
using (var document = new Doc())
{
try{
document.Read(pdfPath);
}catch(ExceptionType e) // where e is the type of exception thrown by ABCPDF10
{
// do something
}
}或者,您可以在使用ABCPDF10读取文件之前检查是否有空文件:
if( new FileInfo(pdfPath).Length == 0 )
{
// empty
}
else
{
// read as before
}发布于 2018-02-28 00:34:11
试一试:
try{
using (var document = new Doc())
{
document.Read(pdfPath);
}
}
catch(Exception){
Console.WriteLine("Exception thrown when attempting to read pdf");
}https://stackoverflow.com/questions/49013434
复制相似问题