wkhtmltopdf 导出pdf
导出网页到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;
}