0

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)

2 Answers2

0

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
}
simonalexander2005
  • 4,338
  • 4
  • 48
  • 92
0

Give this a try:

try{
    using (var document = new Doc())
    {
       document.Read(pdfPath);
    }
}
catch(Exception){
    Console.WriteLine("Exception thrown when attempting to read pdf");
}
Josh Withee
  • 9,922
  • 3
  • 44
  • 62