Skip to main content

How to: Export a PDF Document to a Bitmap

  • 3 minutes to read

Important

You need a license for the DevExpress Office File API Subscription or DevExpress Universal Subscription to use these examples in production code.

The following example demonstrates how to export pages to bitmap images.

Windows

Follow the steps below to perform the export:

  • Create a PdfDocumentProcessor instance and call the LoadDocument method to load a file.
  • Call the PdfDocumentProcessor.CreateBitmap method, and pass the page number and the largestEdgeLength parameter (measured in pixels) as parameters. The largestEdgeLength parameter determines the output image’s height for pages in the portrait orientation and width for landscape pages.

Tip

Pass the PdfPageRenderingParameters instance as the CreateBitmap method parameter to specify a predefined resolution for a PDF page exported to a Bitmap image.

The following example illustrates how to convert pages to bitmap images.

View Example

using DevExpress.Pdf;
using System.Drawing;

static void Main(string[] args)
{

  int largestEdgeLength = 1000;

  using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
  {
      // Load a document.
      processor.LoadDocument("..\\..\\Document.pdf");

      for (int i = 1; i <= processor.Document.Pages.Count; i++)
      {
          // Export pages to bitmaps.
          Bitmap image = processor.CreateBitmap(i, largestEdgeLength);

          // Save the bitmaps.
          image.Save("..\\..\\MyBitmap" + i + ".bmp");
      }
  }

Warning

The CreateBitmap method uses GDI/GDI+ rendering and works only on Windows OS. The PlatformNotSupportedException is thrown on other operating systems. Use the CreateDXBitmap method in non-Windows environments.

Non-Windows Environments

Follow the steps below to perform the export:

  • Create a PdfDocumentProcessor instance and call the LoadDocument method to load a file.
  • Call the PdfDocumentProcessor.CreateDXBitmap method, and pass the page number and the largestEdgeLength parameter (measured in pixels) as parameters. The largestEdgeLength parameter determines the output image’s height for pages in the portrait orientation and width for landscape pages.

Tip

Pass the PdfPageRenderingParameters instance as the CreateDXBitmap method parameter to specify a predefined resolution for a PDF page exported to a Bitmap image.

using DevExpress.Drawing;
using DevExpress.Pdf;

static void Main(string[] args) {

    int largestEdgeLength = 1000;

    using (PdfDocumentProcessor processor = new PdfDocumentProcessor()) {
        // Load a document.
        processor.LoadDocument("..\\..\\Document.pdf");

        for (int i = 1; i <= processor.Document.Pages.Count; i++) {
            // Export pages to bitmaps.
            DXBitmap image = processor.CreateDXBitmap(i, largestEdgeLength);

            // Save the bitmaps.
            image.Save("..\\..\\MyBitmap" + i + ".bmp", DXImageFormat.Bmp);
        }
    }
}

Note

Set the PdfDocumentProcessor.RenderingEngine property to Skia to enable this method on Azure Web Apps.