Extract images from pdf in png or jpg format

Hi


Is it possible to extract the images from a pdf in either png or jpg format? I can see how to get them as svg files but then need to convert them. If this isn’t possible, can you recommend another way of converting them?

Russell

Hi Russell,


Thanks for your inquiry. Please check the documentation and following code snippet. Hopefully it will help you to extract images in your desired format.

Document pdfDocument = new Aspose.Pdf.Document(myDir + “ImageOnLastPagegTurnsBlack.pdf”);

int cnt = 0;
foreach (Page page in pdfDocument.Pages)
{
foreach (XImage image in page.Resources.Images)
{
FileStream outputImage = new FileStream(myDir + “ExtractedImage_” + cnt + “.png”, FileMode.Create);

//save output image
image.Save(outputImage, ImageFormat.Png);
outputImage.Close();
cnt++;
}
}

Please feel free to contact us for any further assistance.

Best Regards,