Example #1
0
        public static string ConvertToImage(string b_file)
        {
            try
            {
                string temp_file       = b_file;
                string partShare       = WebConfigurationManager.AppSettings["ServerLinkFile"];
                string LinkServerLocal = WebConfigurationManager.AppSettings["ServerLocal"];
                if (string.IsNullOrEmpty(LinkServerLocal))
                {
                    b_file = string.Concat("////", partShare, "//", b_file.TrimStart('/'));
                }
                else
                {
                    b_file = string.Concat(LinkServerLocal, "//", b_file.TrimStart('/'));
                }
                //b_file = HttpContext.Current.Server.MapPath("~") + b_file;

                util a = new util();

                if (!File.Exists(b_file))
                {
                    return(string.Empty);
                }
                string b_out = b_file.Replace(".pdf", ".png");
                if (File.Exists(b_out))
                {
                    //b_out = b_out.Replace(HttpContext.Current.Server.MapPath("~"), string.Empty);
                    if (string.IsNullOrEmpty(LinkServerLocal))
                    {
                        b_out = b_out.Replace("////" + partShare, "");
                    }
                    else
                    {
                        b_out = b_out.Replace(LinkServerLocal, "");
                    }
                    return(b_out);
                }
                string temp_temp     = DateTime.Now.ToString("yyyyMMddHHmmss") + ".png";
                string temp_file_png = HttpContext.Current.Server.MapPath("~/Files/Temp/") + temp_temp;

                a.ConvertPdfToPng(b_file, temp_file_png, System.Drawing.Printing.PaperKind.A3);
                b_out = "/Files/Temp/" + temp_temp;
                //a.ConvertPdfToPng(b_file, b_out, System.Drawing.Printing.PaperKind.A3);
                //if (string.IsNullOrEmpty(LinkServerLocal))
                //{
                //    b_out = b_out.Replace("////" + partShare, "");
                //}
                //else
                //{
                //    b_out = b_out.Replace(LinkServerLocal, "");
                //}



                //b_out = b_out.Replace(HttpContext.Current.Server.MapPath("~"), string.Empty);
                return(b_out);
            }
            catch
            {
                return(string.Empty);
            }
        }