网页导出Pdf,样式不变
2021-04-08 14:26
标签:false filename app 样式 empty output pdf sage cat 网页导出Pdf,样式不变 标签:false filename app 样式 empty output pdf sage cat 原文地址:https://www.cnblogs.com/blogcore/p/12459812.htmlpublic static void HtmlToPdf(string urlPath, string fileName)
{
string path = AppDomain.CurrentDomain.BaseDirectory;
string savepath = fileName;
string url = urlPath;
try
{
if (!string.IsNullOrEmpty(url) || !string.IsNullOrEmpty(savepath))
{
Log("PDFHelper_path_null_NEW:" + HttpContext.Current.Request.PhysicalApplicationPath + "wkhtmltopdf.exe");
var p = new Process();
string dllstr = HttpContext.Current.Server.MapPath("~/wkhtmltopdf.exe"); // path + "wkhtmltopdf.exe";
if (System.IO.File.Exists(dllstr))
{
p.StartInfo.FileName = dllstr;
p.StartInfo.Arguments = " \"" + url + "\" \"" + savepath + "\"";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
p.WaitForExit();
}
}
}
catch (Exception ex)
{
Log(ex.Message+ex.StackTrace);
throw new Exception(ex.ToString());
}
}