码迷,mamicode.com
首页 > Web开发 > 详细

网页导出Pdf,样式不变

时间:2020-03-11 01:06:40      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:false   filename   app   样式   empty   output   pdf   sage   cat   

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,样式不变

标签:false   filename   app   样式   empty   output   pdf   sage   cat   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!