How can I get the image from a .pdf file into a System.Drawing.Bitmap?
Use Adobe Acrobat Professional. To extract information from a PDF in Acrobat DC, choose Tools > Export PDF and select an option. To extract text, export the PDF to a Word format or rich text format, and choose from several advanced options that include: Retain Flowing Text.
You may want to try Docotic.Pdf library for the task.
Here is a sample that shows how to create System.Drawing.Bitmap
from an image in a PDF file:
static void GetImagesFromPdfAsBitmaps()
{
string pathToPdf = "";
using (PdfDocument pdf = new PdfDocument(pathToPdf))
{
for (int i = 0; i < pdf.Images.Count; i++)
{
using (MemoryStream ms = new MemoryStream())
{
pdf.Images[i].Save(ms);
// don't forget to rewind stream
ms.Position = 0;
System.Drawing.Image bitmap = System.Drawing.Bitmap.FromStream(ms);
// ... use the bitmap and then dispose it
bitmap.Dispose();
}
}
}
}
The library can also save images to files. The library doesn't resample images (i.e. you'll get exactly the same image as in PDF)
Disclaimer: I work for Bit Miracle, vendor of the library.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With