How do I batch convert PDF to JPEG/PNG in .NET?

Q: How do I batch convert PDFs to JPEG/PNG in .NET?
A: As a starting point you may want to take a look at in the file section of this group. Please note that
this sample is not included as part of standard PDFNet distribution.

You may also want to take at PDFDraw sample (

// Copyright (c) 2001-2010 by PDFTron Systems Inc. All Rights

using System;
using System.IO;
using pdftron;
using pdftron.Common;
using pdftron.Filters;
using pdftron.SDF;
using pdftron.PDF;

// This sample shows how to use pdftron.PDF.PDFDraw to batch convert
// PDFs stored under a given folder to JPEG.

namespace PDFNetSamples
  class PDF2ImageBatch
    static int counter = 0;
    static Obj jpeg_hint = null;

    public static void ProcessDir(string srcDir, string outDir)
      // Process the list of files found in the directory.
      string[] fileEntries = Directory.GetFiles(srcDir, "*.pdf");
      foreach (string fileName in fileEntries)

        using (PDFDoc doc = new PDFDoc(fileName))
          if (doc.InitSecurityHandler())
          { // No password required.
            using (PDFDraw draw = new PDFDraw())
              for (PageIterator i = doc.GetPageIterator(); i.HasNext();
                string fname = outDir + "fileName_" + (counter++).ToString() +
                draw.Export(i.Current(), fname, "jpeg", jpeg_hint);

      // Recurse into subdirectories of this directory.
      string[] subdirEntries = Directory.GetDirectories(srcDir);
      foreach (string subdir in subdirEntries)
        // Do not iterate through reparse points
        if ((File.GetAttributes(subdir) & FileAttributes.ReparsePoint)
          != FileAttributes.ReparsePoint)
          ProcessDir(subdir, outDir);

    static void Main(string[] args)

        // Setup image export hint. The hint can be used to control
        // compression, quality, color spaces, etc.
        ObjSet objset = new ObjSet();
        jpeg_hint = objset.CreateArray();

        ProcessDir("../../../../TestFiles/", "../../../../TestFiles/
      catch (PDFNetException e)