This demo uses the DevExpress PDF Document API (PdfDocumentProcessor) to extract images from a PDF document. You can process the predefined sample file or supply your own document. To do the latter, select Upload a File in the file selection drop-down menu.
Specify extracted image resolution and Page Range Settings. Use the Extract Images as ... button to specify the output format, extract images, and download the result.
using DevExpress.Pdf;
using DevExpress.Drawing;
IReadOnlyList<Stream> ExtractImages(Stream documentStream, DXImageFormat imageFormat, int resolution, IEnumerable<int> pageRange) {
using var processor = new PdfDocumentProcessor();
var result = new List<Stream>();
processor.LoadDocument(documentStream);
if (!pageRange.Any())
pageRange = Enumerable.Range(0, processor.Document.Pages.Count);
foreach(var index in pageRange) {
if(index < 0 || index >= processor.Document.Pages.Count)
continue;
var page = processor.Document.Pages[index];
var images = processor.GetDXImages(
new PdfDocumentArea(page.GetPageIndex(), page.MediaBox),
resolution);
foreach(var image in images) {
var imageStream = new MemoryStream();
image.Save(imageStream, imageFormat);
result.Add(imageStream);
}
}
return result;
}