5

I would like to grab a PDF from my hard disc and convert it to a bitmap image.

How can I accomplish this using PdfiumViewer?

Nick is tired
  • 6,860
  • 20
  • 39
  • 51

2 Answers2

3

SOLUTION:

1) Add this nuget to your project: https://www.nuget.org/packages/PdfiumViewer/ (if it doesn't work, add this one too: https://www.nuget.org/packages/PdfiumViewer.Native.x86_64.v8-xfa/)

2) Add the reference "PdfiumViewer" to your project References

3) Use the following code:

using (var pdfDocument = PdfiumViewer.PdfDocument.Load(@"document.pdf"))
{
    var bitmapImage = pdfDocument.Render(0, 300, 300, true);
    bitmapImage.Save(@"image.bmp", ImageFormat.Bmp);
}
Adriaan
  • 17,741
  • 7
  • 42
  • 75
3

You can use the PdfDocument.Render method:

void renderPdfToFile(string pdfFilename, string outputImageFilename, int dpi) {
    using (var doc = PdfDocument.Load(pdfFilename)) {               // Load PDF Document from file
        for (int page = 0; page < doc.PageCount; page++) {          // Loop through pages
            using (var img = doc.Render(page, dpi, dpi, false)) {   // Render with dpi and with forPrinting false
                img.Save($"page_{page}_{outputImageFilename}");     // Save rendered image to disc
            }
        }
    }
}
Himbeer
  • 141
  • 1
  • 3
  • 9