Extract Images from PDF | |
SelectPdf Library for .NET extracts the raster images a PDF document carries - photographs, scans, logos - with PdfImageExtractor. Where Convert PDF Pages to Images renders whole pages, the extractor returns the pictures themselves at the resolution they are stored in. Text and vector graphics are not images and are not returned.
Load the document with one of the Load overloads, then get the images as encoded bytes with ExtractImages or write them to files with Save. Images come in the order they appear, page by page.
StartPageNumber and EndPageNumber - the pages searched (1-based; an end of 0 means up to the last page).
UserPassword - the password of an encrypted document.
ImagesFormat - the format the images are returned and written in: PNG (the default, lossless), JPEG, BMP or TIFF.
ImagesPath and ImagesPrefix - where Save writes the images, named prefix + page number + "-" + the image's number on that page (image-1-1.png, image-1-2.png, image-2-1.png, ...).
using (PdfImageExtractor extractor = new PdfImageExtractor()) { extractor.Load("catalog.pdf"); // option 1: the images as PNG byte arrays byte[][] images = extractor.ExtractImages(); for (int i = 0; i < images.Length; i++) System.IO.File.WriteAllBytes("image" + (i + 1) + ".png", images[i]); // option 2: the images of pages 2 to 4 written as JPEG files extractor.StartPageNumber = 2; extractor.EndPageNumber = 4; extractor.ImagesFormat = PdfImageFormat.Jpeg; extractor.ImagesPath = "images"; extractor.ImagesPrefix = "catalog-"; extractor.Save(); }