wkhtmltopdf参数设置和下载PDF
来源:互联网 发布:js 鼠标自动隐藏 编辑:程序博客网 时间:2024/06/04 20:38
string fileName = Guid.NewGuid().ToString(); string url = Request.Url.ToString(); string savepath = System.Web.HttpContext.Current.Server.MapPath("~/upfile/") + fileName + ".pdf"; try { if (!string.IsNullOrEmpty(url) || !string.IsNullOrEmpty(savepath)) { Process p = new Process(); string dllstr = @"D:\wkhtmltopdf\wkhtmltopdf.exe"; StringBuilder paramsBuilder = new StringBuilder(); paramsBuilder.Append("--print-media-type "); paramsBuilder.Append("--disable-smart-shrinking "); paramsBuilder.Append("--margin-top 0mm --margin-bottom 0mm --margin-right 0mm --margin-left 0mm "); //paramsBuilder.Append("--page-size A4 ");//当使用页面参数时,宽高参数无效 paramsBuilder.Append("--page-width 310mm "); paramsBuilder.Append("--page-height 310mm "); paramsBuilder.Append("--no-background "); paramsBuilder.AppendFormat("\"{0}\" \"{1}\"",url, savepath); if (System.IO.File.Exists(dllstr)) { ProcessStartInfo psi = new ProcessStartInfo(); psi.FileName = dllstr; psi.Arguments = paramsBuilder.ToString(); psi.UseShellExecute = false; psi.RedirectStandardOutput = true; psi.RedirectStandardError = true; psi.RedirectStandardInput = true; psi.CreateNoWindow = true; p.StartInfo = psi; p.Start(); p.WaitForExit(); try { FileStream fs = new FileStream(savepath, FileMode.Open); byte[] file = new byte[fs.Length]; fs.Read(file, 0, file.Length); fs.Close(); System.Web.HttpContext.Current.Response.Clear(); System.Web.HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=" + fileName + ".pdf");//強制下載 System.Web.HttpContext.Current.Response.ContentType = "application/octet-stream"; System.Web.HttpContext.Current.Response.BinaryWrite(file); } catch (Exception e) { throw e; } } } } catch (Exception e) { throw e; }
0 0
- wkhtmltopdf参数设置和下载PDF
- 使用wkhtmltopdf打印pdf
- HTML转PDF工具(wkhtmltopdf),支持widows和linux
- HTML转PDF工具(wkhtmltopdf),支持widows和linux
- 使用wkhtmltopdf完成文件的转换和下载
- wkhtmltopdf.exe >>html to PDF
- 【wkhtmltopdf】关于页面打印pdf
- html转pdf错误wkhtmltopdf
- HTML转PDF工具(wkhtmltopdf)介绍,支持widows和linux
- HTML转PDF工具(wkhtmltopdf)介绍,支持widows和linux
- HTML转PDF工具(wkhtmltopdf)介绍,支持widows和linux
- HTML转换成PDF工具:wkhtmltopdf
- wkhtmltopdf将网页转换成PDF
- HTML 转 PDf 方法一 wkhtmltopdf.exe
- Java操作wkhtmltopdf实现Html转PDF
- Java操作wkhtmltopdf实现Html转PDF
- 使用wkhtmltopdf将html转为pdf
- php用wkhtmltopdf把html生成pdf
- Android 读取本地(SD卡)图片
- iOS-OC中加载html5调用html方法和修改HTML5内容
- saiku前端query.js
- Python时间处理:datetime模块
- 标日初上-第4課
- wkhtmltopdf参数设置和下载PDF
- 求组合数
- springMVC+Hibernate 框架整合
- JDBC(三)
- hdu 2833 WuKong(floyd变形)
- QQ侧滑效果的实现与思考
- 学习正则表达式,一看就懂
- Xcode莫名其妙的崩溃
- 基本控件使用