使用Pechkin将HTML网页转换为PDF
Pechkin开源组件使用wkhtmlbox,可以解析CSS样式,将网页转换为PDF文件,
支持URL,或者HTML字符串
1, 从NuGet程序管理器中获得Pechkin
SynchronizedPechkin sc = new SynchronizedPechkin(new GlobalConfig()
.SetMargins(new Margins() { Left = 0, Right = 0, Top = 0, Bottom = 0 }) //设置边距
.SetPaperOrientation(true)); //设置纸张方向为横向
//.SetPaperSize(340, 594)); //设置纸张大小50mm * 100mm
ObjectConfig oc = new ObjectConfig();
oc.SetPageUri("http://localhost:40146/Styles/HTMLPage2.htm");
byte[] buf = sc.Convert(oc);
Response.AddHeader("content-disposition", "attachment;filename=1.pdf");
Response.ContentType = "application/octet-stream";
Response.BinaryWrite(buf);