wkhtmltopdf 导出pdf

时间:2016-08-13 07:06:25
【文件属性】:
文件名称:wkhtmltopdf 导出pdf
文件大小:5.52MB
文件格式:EXE
更新时间:2016-08-13 07:06:25
pdf wkhtmltopdf 导出网页到pdf工具。。 public static bool HtmlToPdf(string url, string path) { try { if (string.IsNullOrEmpty(url) || string.IsNullOrEmpty(path)) return false; Process p = new Process(); string str = System.Web.HttpContext.Current.Server.MapPath("~/wkhtmltopdf.exe"); if (!System.IO.File.Exists(str)) return false; string switches = "--print-media-type "; switches += "--margin-top 0mm --margin-bottom 4mm --margin-right 0mm --margin-left 0mm "; switches += "--page-size A4 "; // switches += "--no-background "; switches += "--redirect-delay 100%"; //p.SessionId == "1"; p.StartInfo.FileName = str; p.StartInfo.Arguments = switches + " " + url + " " + path; //p.StartInfo.Arguments = " \"" + url + "\" " + path; p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardInput = true; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.RedirectStandardError = true; p.StartInfo.CreateNoWindow = true; p.Start(); System.Threading.Thread.Sleep(800); // p.SessionId p.WaitForExit(); p.Close(); return true; } catch (Exception ex) { HttpContext.Current.Response.Write(ex); } return false; }

网友评论

  • 很好用,谢谢你的分享
  • 很好用,谢谢分享
  • 主要是为了下能完整运行的项目,这个只是组件