方法一:
openhtmltopdf.png
using (WebClient wc = new WebClient())
{
wc.Encoding = Encoding.UTF8;
// string html = wc.DownloadString(url);
string html = File.ReadAllText("C://ssss7.html");
//var pdf = Pdf
//.From(html)
//.WithGlobalSetting("orientation", "Landscape")
//.WithObjectSetting("web.defaultEncoding", "utf-8")
//.Content();
var pdf = Pdf
.From(html)
.OfSize(PaperSize.A4)
.WithoutOutline()
.WithMargins(2.5.Centimeters())
.Portrait()
.Comressed()
.Content();
File.WriteAllBytes("C://fffff9.pdf", pdf);//保存在本地
//HtmlToPdf toPdf = new HtmlToPdf();
//toPdf.Options.PdfPageSize = PdfPageSize.A4;
//toPdf.Options.MarginRight = 3;
//toPdf.Options.MarginLeft = 3;
//PdfDocument pdf = toPdf.ConvertHtmlString(html); ;
//pdf.Save("C://fffff10.pdf");
//pdf.Close();
}
方法二: SelectPdf
HtmlToPdf toPdf = new HtmlToPdf();
toPdf.Options.PdfPageSize = PdfPageSize.A4;
toPdf.Options.MarginRight = 3;
toPdf.Options.MarginLeft = 3;
PdfDocument pdf = toPdf.ConvertHtmlString(html); ;
pdf.Save("C://fffff10.pdf");
pdf.Close();
结果:
pdf.png
网友评论