首页 > Web开发 > 详细

网页导出Pdf,样式不变

时间:2020-03-11 01:30:04      阅读:109      评论:0      收藏:0      [点我收藏+]
public 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());
        }
    }

网页导出Pdf,样式不变

原文:https://www.cnblogs.com/blogcore/p/12459812.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!