PdfiumViewer icon indicating copy to clipboard operation
PdfiumViewer copied to clipboard

Program crashes on image export

Open mtozlu opened this issue 8 years ago • 0 comments

Hello,

I render pages to images from the attached PDF file. All images are exported nicely. But when disposing document object, the program crashes. There is no way to handle the exception, it suddenly crashes. Please mind that the below code works fine in most of my PDFs, it only crashes for this particular one. pdfFile.pdf

Here is my code for image rendering;

using (var document = PdfDocument.Load(pdfFile))
{
  for (var pageNumber = 0; pageNumber < document.PageCount; pageNumber++)
  {
    var targetFile = System.IO.Path.Combine(targetPath, string.Format("{0:000}", pageNumber + 1));
    using (var image= document.Render(pageNumber, (int)document.PageSizes[pageNumber].Width, (int)document.PageSizes[pageNumber].Height, 96, 96, false))
    {
      image.Save(targetFile  + ".jpg", ImageFormat.Jpeg);
    }
  }
} // This is where the program crashes

Thanks.

mtozlu avatar Nov 23 '17 17:11 mtozlu