码迷,mamicode.com
首页 > 其他好文 > 详细

将页面转化为pdf的实现方法

时间:2015-09-28 17:32:15      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:

1.实现代码把html转化为pdf主要是使用wkhtmltopdf.exe工具生成,在获取转化的地址,创建一个进程,把地址传递到进程参数中进行调用wkhtmltopdf.exe工具打印

2.代码片段//调用工具部分

      /// <summary>         /// 启动Wkhtmltopdf         /// </summary>         /// <param name="parms">启动参数</param>         /// <returns></returns>         public void StartWK(string parms, bool IsNoHead = true)         {             try             {                 Process proc = new Process();                 string resource = HttpContext.Current.Server.MapPath("~/Content/wkhtmltopdf/bin");                 string dllstr = string.Format(resource + "\\wkhtmltopdf.exe");

                if (System.IO.File.Exists(dllstr))                 {                     proc.StartInfo.FileName = dllstr;                     string strArguments = IsNoHead ? string.Empty : " --margin-top 20 --margin-bottom 20 --header-spacing 2 --footer-spacing 1 --footer-font-size 7 --footer-center \"第[page]页/共[topage]页\" ";                     strArguments += parms;

                    proc.StartInfo.Arguments = strArguments;                     proc.StartInfo.UseShellExecute = false;                     proc.StartInfo.RedirectStandardInput = true;                     proc.StartInfo.RedirectStandardOutput = true;                     proc.StartInfo.RedirectStandardError = true;                     proc.StartInfo.CreateNoWindow = true;                     proc.Start();                     proc.WaitForExit();                 }                 else                 {                     throw new Exception("wkhtmltopdf.exe启动异常!");                 }             }             catch (Exception)             {                 throw;             }         }

 

将页面转化为pdf的实现方法

标签:

原文地址:http://www.cnblogs.com/zhangjinpeng/p/4844504.html

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