using System;
using System.IO;
using Foxit.PDF.Rasterizer;

namespace JpegImage_Example
{
    class Program
    {
        static void Main(string[] args)
        {
            string pdfPath = GetPDFPath();

            //Create a PdfRasterizer
            PdfRasterizer rasterizer = new PdfRasterizer(Path.Combine(pdfPath, "DocumentA.pdf"));

            // Create a JpegImageFormat object.
            JpegImageFormat jpegImageFormat = new JpegImageFormat(100);

            // Create a FixedImageSize object with required width and height.
            FixedImageSize fixedImageSize = new FixedImageSize(595, 841);

            // Save the image.
            rasterizer.Draw("JpegImage.jpg", jpegImageFormat, fixedImageSize);
        }
        static string GetPDFPath()
        {
            string pdfPath = AppDomain.CurrentDomain.BaseDirectory;
            if (pdfPath.EndsWith(new string(Path.DirectorySeparatorChar, 1)))
            {
                pdfPath = Path.GetDirectoryName(pdfPath);
            }
            while (Directory.Exists(pdfPath) && !Directory.Exists(Path.Combine(pdfPath, "PDFs")))
            {
                pdfPath = Path.GetDirectoryName(pdfPath);
            }
            if (pdfPath == null || !Directory.Exists(Path.Combine(pdfPath, "PDFs")))
            {
                throw new Exception("File path for pdf files could not be found.");
            }

            return pdfPath + "\\PDFs";
        }
    }
}
