public static List <string> Convert(string filename, string img_filename, OutputFormat output_format, int resolution = 300)
        {
            string        error  = null;
            List <string> errors = new List <string>();
            String        gsPath = GetProgramFilePath("gsdll32.dll", out error);

            if (!System.IO.File.Exists(gsPath))
            {
                File.WriteAllBytes(gsPath, Properties.Resources.gsdll32);
            }
            if (error != null)
            {
                errors.Add(error);
            }

            if (File.Exists(img_filename))
            {
                File.Delete(img_filename);
            }

            //This is the object that perform the real conversion!
            PDFConvert converter = new PDFConvert();

            //Ok now check what version is!
            GhostScriptRevision version = converter.GetRevision();

            //lblVersion.Text = version.intRevision.ToString() + " " + version.intRevisionDate;
            bool Converted = false;

            //Setup the converter
            converter.RenderingThreads = -1;
            converter.TextAlphaBit     = -1;
            converter.TextAlphaBit     = -1;

            converter.FitPage      = true;
            converter.JPEGQuality  = mPrintQuality; //80
            converter.OutputFormat = output_format.ToString();

            converter.OutputToMultipleFile = false;
            converter.FirstPageToConvert   = -1;
            converter.LastPageToConvert    = -1;

            converter.ResolutionX = converter.ResolutionY = resolution;

            System.IO.FileInfo input = new FileInfo(filename);
            if (!string.IsNullOrEmpty(mGSPath))
            {
                converter.GSPath = mGSPath;
            }
            Converted = converter.Convert(input.FullName, img_filename);

            return(errors);
        }
        private string ConvertPdf2Img(string filename)
        {
            if (!System.IO.File.Exists(Application.StartupPath + "\\gsdll32.dll"))
            {
                //lblDllInfo.Font = new Font(lblDllInfo.Font.FontFamily, 10, FontStyle.Bold);
                //lblDllInfo.ForeColor = Color.Red;
                lblStatus.Text = "Download: http://mirror.cs.wisc.edu/pub/mirrors/ghost/GPL/gs863/gs863w32.exe";
                MessageBox.Show("The library 'gsdll32.dll' required to run this program is not present! download GhostScript and copy \"gsdll32.dll\" to this program directory");
                return("");
            }

            //This is the object that perform the real conversion!
            PDFConvert converter = new PDFConvert();

            //Ok now check what version is!
            GhostScriptRevision version = converter.GetRevision();

            //lblVersion.Text = version.intRevision.ToString() + " " + version.intRevisionDate;
            bool Converted = false;

            //Setup the converter
            //Setup the converter
            converter.RenderingThreads = -1;
            converter.TextAlphaBit     = -1;
            converter.TextAlphaBit     = -1;

            converter.FitPage      = false;
            converter.JPEGQuality  = 10;
            converter.OutputFormat = "png256";
            converter.ResolutionX  = 500;
            converter.ResolutionY  = 500;

            converter.OutputToMultipleFile = false;
            converter.FirstPageToConvert   = -1;
            converter.LastPageToConvert    = -1;

            System.IO.FileInfo input = new FileInfo(filename);

            //string output = string.Format("{0}\\Images\\tmp\\{1}{2}", Application.StartupPath, DateTime.Now.ToString("yyyyMMddHHmmss"), ".png");
            string output  = string.Format("{0}\\Images\\tmp\\{1}{2}", Application.StartupPath, DateTime.Now.ToString("yyyyMMddHHmmss"), ".png");
            int    indexer = 0;

            while (File.Exists(output))
            {
                output = string.Format("{0}\\Images\\tmp\\{1}{2}{3}", Application.StartupPath, DateTime.Now.ToString("yyyyMMddHHmmss"), indexer++, ".png");
            }

            //If the output file exist alrady be sure to add a random name at the end until is unique!

            //Just avoid this code, isn't working yet
            //if (checkRedirect.Checked)
            //{
            //    Image newImage = converter.Convert(input.FullName);
            //    Converted = (newImage != null);
            //    if (Converted)
            //        pictureOutput.Image = newImage;
            //}
            //else
            converter.GSPath = string.Format("{0}\\gs", Application.StartupPath);
            Converted        = converter.Convert(input.FullName, output);
            //txtArguments.Text = converter.ParametersUsed;
            //if (Converted)
            //{
            //    lblInfo.Text = string.Format("{0}:File converted!", DateTime.Now.ToShortTimeString());
            //    txtArguments.ForeColor = Color.Black;
            //}
            //else
            //{
            //    lblInfo.Text = string.Format("{0}:File NOT converted! Check Args!", DateTime.Now.ToShortTimeString());
            //    txtArguments.ForeColor = Color.Red;
            //}

            return(output);
        }