zoukankan      html  css  js  c++  java
  • 将页面转化为pdf的实现方法

    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;             }         }

  • 相关阅读:
    22个免费和高级WordPress的滑块插件
    asp.net mvc 4.0的部署
    苹果公布2011年度最佳iOS应用
    18 个 jQuery Mobile 开发贴士和教程
    给asp.net mvc小白扫盲用的
    JM8.6中的MV计算及上层块预测方法
    CAVLC算法解析
    JM8.6中的关于写比特流的问题
    JM8.6中对cofAC及相关数组的探讨
    JM8.6中三个RDCost函数的对比分析
  • 原文地址:https://www.cnblogs.com/zhangjinpeng/p/4844504.html
Copyright © 2011-2022 走看看