Skip to main content
All docs
V26.1
  • New DevExpress PDF Document API: Export PDF Pages to Images

    • 2 minutes to read

    The new PDF Document API lets you export PDF pages as images. You can export one or more pages to Bitmap or SVG format.

    Call the PdfDocument.ExportToImages method and pass an array of page indexes to export the corresponding pages to images.

    The following code snippet exports the first, third, and fifth pages of a PDF document to BMP images:

    using DevExpress.Docs.Pdf;
    using DevExpress.Drawing;
    
    using (PdfDocument pdfDocument =
        new PdfDocument(File.OpenRead(@"document_001.pdf")))
    {
        var images = pdfDocument.ExportToImages(new int[] { 1, 3, 5 });
    
        for (int i = 0; i < images.Length; i++)
        {
            using (var stream = new FileStream(String.Format("document_001_page_{0}.bmp", i + 1), FileMode.Create))
            {
                images[i].Save(stream, DXImageFormat.Bmp);
            }
        }
    }
    

    The ImageExportOptions class allows you to specify the image format, resolution, and other export options. Pass the ImageExportOptions object as the PdfDocument.ExportToImages method parameter to apply these options.

    The following code snippet exports the first, third, and fifth pages of a PDF document to BMP images at 300 DPI and with a maximum edge length of 1000 pixels.

    using DevExpress.Docs.Pdf;
    using DevExpress.Drawing;
    
    using (PdfDocument pdfDocument =
        new PdfDocument(File.OpenRead(@"document_001.pdf")))
    
    {
        ImageExportOptions exportOptions = new ImageExportOptions();
        exportOptions.ImageExportType = ImageExportType.Bitmap;
        exportOptions.Resolution = 300;
        exportOptions.LargestEdgeLength = 1000;
    
        var images = pdfDocument.ExportToImages(exportOptions, new int[] { 1, 3, 5 });
    
        for (int i = 0; i < images.Length; i++)
        {
            using (var stream = new FileStream(String.Format("document_001_page_{0}.bmp", i + 1), FileMode.Create))
            {
                images[i].Save(stream, DXImageFormat.Bmp);
            }
        }
    }