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

  • 相关阅读:
    使用 Apache OpenJPA 开发 EJB 3.0 应用,第 3 部分: 实体继承
    使用 Apache OpenJPA 开发 EJB 3.0 应用,第 2 部分: 开发第一个 Open JPA 应用
    使用 Apache OpenJPA 开发 EJB 3.0 应用,第 6 部分: 处理实体生命周期事件的回调
    http://www.oschina.net/question/129540_20547
    tomcat6实现远程调试
    FluorineFx和Flex配置
    今天才开通这个博客呀!
    vue中install方法
    Vue.nextTick 的原理和用途
    vue3.0中使用nextTick
  • 原文地址:https://www.cnblogs.com/zhangjinpeng/p/4844504.html
Copyright © 2011-2022 走看看