using System;
using System.IO;
using O2S.Components.PDFRender4NET.WPF;

namespace PDF2Image
{
    class Program
    {
        /// <summary>
        /// Main method.
        /// </summary>
        /// <param name="args">The args.</param>
        [STAThread]
        static void Main(string[] args)
        {
            // Load the PDF file.
            PDFFile pdfFile = PDFFile.Open("..\\SupportFiles\\sample.pdf");

            // Get the image stream
            Stream imageStream = pdfFile.GetPageImage(0, 39, 39, OutputImageType.BMP);

            // Save the stream to disk
            FileStream fs = File.OpenWrite(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\pageimage.bmp");
            byte[] imageBytes = ((MemoryStream)imageStream).ToArray();
            fs.Write(imageBytes, 0, imageBytes.Length);
            fs.Close();
        }
    }
}
