网页导出Pdf,样式不变

2021-04-08 14:26

阅读:589

标签: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


评论


亲,登录后才可以留言!