簡體   English   中英

ABCPDF10引發PDFException

[英]ABCPDF10 throws PDFException

我正在使用abcpdf10讀取pdf文件。 每當我的代碼遇到一個空的pdf文件(0kb)時,document.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");
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM