標籤:ror name ges new 字元 大小 image res paper
Pechkin開源組件使用wkhtmlbox,可以解析CSS樣式,將網頁轉換為PDF檔案,
支援URL,或者HTML字串
1, 從NuGet程式管理器中獲得Pechkin
GlobalConfig config = new GlobalConfig(); SimplePechkin pechkin = new SimplePechkin(config); ObjectConfig objectConfig = new ObjectConfig(); objectConfig.SetPrintBackground(true) .SetLoadImages(true) .SetAffectPageCounts(true) .SetPageUri("http://www.abc.com/"); byte[] bytePDF = pechkin.Convert(objectConfig);, File.WriteAllBytes("F:\\PDFName.pdf", bytePDF); 2,CPechkin,網友對Pechkin進行了封裝,也可以從NuGet獲得
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);
使用Pechkin將HTML網頁轉換為PDF