ABCPDF10 throws PDFException



我正在使用ABCPDF10读取PDF文件。每当我的代码遇到一个空的PDF文件(0KB(时,Read.Read(PDFPath(抛出异常。

using (var document = new Doc())
{
   document.Read(pdfPath);
}

如果我的代码遇到空文件,我需要忽略并继续。我不确定该怎么做。使用C#和ABCPDF10(WebSuperGoo(

您可以使用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
}

尝试一下:

try{
    using (var document = new Doc())
    {
       document.Read(pdfPath);
    }
}
catch(Exception){
    Console.WriteLine("Exception thrown when attempting to read pdf");
}

最新更新