2014年10月30日 星期四

網頁轉PDF

問題:
網頁轉PDF。
解決方式:

var document = new HtmlToPdfDocument
{
GlobalSettings =
{
ProduceOutline = true,
DocumentTitle = "PDF Title", 
PaperSize = System.Drawing.Printing.PaperKind.A4, 
Orientation = TuesPechkin.GlobalSettings.PaperOrientation.Landscape, 
Margins = 
{ 
Top = 1.5, 
Right = 1, 
Bottom = 1, 
Left = 1.25, 
Unit = Unit.Centimeters 
} 
}, 
Objects = { 
new ObjectSettings { PageUrl = URL } 
} 
} 
IPechkin sc2 = Factory.Create();
var buf = sc2.Convert(document);
Response.Clear();
Response.HeaderEncoding = System.Text.Encoding.GetEncoding(950);
Response.AddHeader("Content-Disposition", "attachment; filename=Filename.pdf");
Response.ContentType = "application/octet-stream";
Response.BinaryWrite(buf);


參考:TuesPechkin

2014年1月8日 星期三