Search code examples
c#abcpdf

ABCPDF10 throws PDFException


I am using abcpdf10 to read pdf files. Whenever my code encounters an empty pdf file (0kb), document.Read(pdfPath) throws exception.

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

If my code encounters empty file I need to ignore and continue. I am not sure how to do this. Using C# and ABCPDF10 (websupergoo)


Solution

  • You can use a try-catch block to catch exceptions:

    using (var document = new Doc())
    {
       try{
       document.Read(pdfPath);
       }catch(ExceptionType e) // where e is the type of exception thrown by ABCPDF10
       {
           // do something
       }
    }
    

    Alternatively, you can check for an empty file before reading it with ABCPDF10:

    if( new FileInfo(pdfPath).Length == 0 )
    {
      // empty
    }
    else
    {
        // read as before
    }