Powerful all-in-one PDF library for .NET
VS 2005/2008/2010/2012/2013

How To Convert PDF To Image Formats In .NET

Learn to export PDF pages as raster images.
By V. Subhash

In Version 5 of PDFOne .NET, a new SaveAsImage() method was introduced, which internally use this code. You do not have to go through the metafile-creation process.

In an earlier article, we learned how to export PDF documents to Windows metafiles. This was a bit complicated because .NET does not have an encoder for EMF or WMF, and we had to manage with some unmanaged calls. EMF files are useful only Windows. For wider use, we may need BMP, JPEG, PNG or other raster image formats.

Exporting PDF page content to a raster image format is much more simpler. (In the older article, there were code comments that hinted as much.) The example source code in this article shows us how.

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;
using Gnostice.PDFOne;

namespace PDFOne_dotNET_Examples {

  class Convert_PDF_To_Images {

    static void Main(string[] args) {

      // Create a metafile
      Metafile metafile;

      // Load a PDF document
      PDFDocument doc =
         new PDFDocument("Your license key");
      // Load the input document and get its page count
      Console.WriteLine("Document loaded.");

      // Iterate through all pages in the document
      for (int i = 1; i <= doc.GetPageCount(); i++) {

          // Export current page as a metafile
          metafile = doc.GetPageMetafile(i);

          // Save metafile to PNG and JPEG formats
              "image_of_page_#" + i.ToString() + ".png",
              "image_of_page_#" + i.ToString() + ".jpg",

          Console.Write("\rPage #1-" + i + " exported.");

          // Release any resources used by the metafile


      // Clean up
      Console.WriteLine("\nDocument closed.");

      Console.WriteLine("Press Enter to exit.");


What we do here is iterate through all the pages, export page contents as a metafile, and save the metafile as a PNG and JPEG image. That's it. (The program would have been smaller if it were not for the obsession with console output. ☺)


Our .NET Developer Tools
Gnostice Document Studio .NET

Multi-format document-processing component suite for .NET developers.


A .NET PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, and bookmark PDF documents in .NET applications.

Our Delphi/C++Builder developer tools
Gnostice Document Studio Delphi

Multi-format document-processing component suite for Delphi/C++Builder developers, covering both VCL and FireMonkey platforms.

eDocEngine VCL

A Delphi/C++Builder component suite for creating documents in over 20 formats and also export reports from popular Delphi reporting tools.

PDFtoolkit VCL

A Delphi/C++Builder component suite to edit, enhance, view, print, merge, split, encrypt, annotate, and bookmark PDF documents.

Our Java developer tools
XtremeDocumentStudio (for Java)

Multi-format document-processing component suite for Java developers.

PDFOne (for Java)

A Java PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, bookmark PDF documents in Java applications.

Our Platform-Agnostic Cloud and On-Premises APIs

Cloud-hosted and On-Premises REST-based document-processing and document-viewing APIs

Privacy | Legal | Feedback | Newsletter | Blog | Resellers © 2002-2019 Gnostice Information Technologies Private Limited. All rights reserved.