empira / PDFsharp-1.5

A .NET library for processing PDF
MIT License
1.28k stars 588 forks source link

SharpZipBaseException on calling XGraphics.FromPdfPage #5

Closed wbokkers closed 8 years ago

wbokkers commented 8 years ago

For a lot of PDF pages I get a SharpZipBaseException when calling XGraphics.FromPdfPage. The exception is thrown in InflaterInputStream.Fill() with message "Unexpected EOF".

I can 'fix' this problem using a hack in InflaterInputStream.Read:

public override int Read(byte[] buffer, int offset, int count)

   ....
if (inf.IsNeedingInput)
{
    try
    {
        Fill();
    }
    catch(SharpZipBaseException)
    { // WB! early EOF: apparantly not a big deal for some PDF pages: break out of the loop.
        break; 
    }
}
     ...
ThomasHoevel commented 8 years ago

The hack was imported to the current internal build of PDFsharp.