protected SingleConvertToPDF() { try { string sPathExe = "C:\\Program Files (x86)\\Prince\\Engine\\bin\\prince.exe"; if (File.Exists(sPathExe)) { // instantiate Prince by specifying the full path to the engine executable prn = new Prince("C:\\Program Files (x86)\\Prince\\Engine\\bin\\prince.exe"); // specify the log file for error and warning messages // make sure that you have write permissions for this file sPathDirectory = System.AppDomain.CurrentDomain.BaseDirectory; prn.SetLog(sPathDirectory + "\\HtmlToPdf\\logPrinceHtmlToPdf.txt"); // apply a CSS style sheet (optional) prn.AddStyleSheet(sPathDirectory + "\\css\\bootstrap-theme.css"); prn.AddStyleSheet(sPathDirectory + "\\css\\bootstrap-theme.min.css"); prn.AddStyleSheet(sPathDirectory + "\\css\\bootstrap.min.css"); prn.AddStyleSheet(sPathDirectory + "\\css\\UserPourPdf.css"); // apply an external JavaScript file (optional) //prn.AddScript("C:\\docs\\js\\test.js"); } else { sInitLog = "Fichier exe Prince n'esiste pas en : " + sPathExe; SingleLogFileAsXml.Instance().AjouteLog("Init", sInitLog); } } catch (Exception ex) { sInitLog = ex.Message; SingleLogFileAsXml.Instance().AjouteLog("Init", "SingleConvertToPDF : Exception : " + ex.Message); } }
private static void AttachPrinceFilter(HttpApplication httpApplication) { var path = GetPrincePath(httpApplication); var prince = new Prince(path); prince.SetBaseURL(httpApplication.Request.Url.AbsoluteUri); prince.SetLog("prince.log"); prince.SetInsecure(true); httpApplication.Response.Filter = new PrinceFilter(prince, httpApplication.Response.Filter); }
private byte[] MakePdf(string html) { try { var prince = new Prince(HttpContext.Current.Server.MapPath("~/CommandLine/PrinceEngine/bin/prince.exe")); prince.SetLicenseFile(HttpContext.Current.Server.MapPath("~/CommandLine/PrinceEngine/license/license.dat").Replace("\\", "/")); //prince.SetLicenseFile("../license/license.dat"); prince.SetHtml(true); //prince.SetFileRoot(tempPath.EndsWith("\\") ? tempPath.Substring(0, tempPath.Length - 1) : tempPath); prince.SetLog(HttpContext.Current.Server.MapPath("~/App_Data/Blobs/prince.log")); using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(html)) { Position = 0 }) { using (var pdf = new MemoryStream()) { prince.ConvertMemoryStream(ms, pdf); return(pdf.ToArray()); } } } catch (Exception ex) { Debug.WriteLine(ex.Message); return(null); } finally { } }