Aspose.PDF如何转换HTML为PDF文件

作者:控件中国网   出处:控件中国网   2015-09-01 09:49:22   阅读:25

Aspose.Pdf是一款专业的PDF文档处理、创建、读取和转换控件,支持把多种格式文件转换为PDF,也支持把PDF转换为多种其他文件格式,这篇文章主要介绍Aspose.Pdf控件如何利用控件提供的API把HTML页面完全转换为PDF,具体可以参考下面的部分代码:

// Instantiate an object PDF class
Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf();
// add the section to PDF document sections collection
Aspose.Pdf.Generator.Section section = pdf.Sections.Add();
          
// Read the contents of HTML file into StreamReader object
StreamReader r = File.OpenText(@"D:/pdftest/HTML2pdf.html");
//Create text paragraphs containing HTML text
Aspose.Pdf.Generator.Text text2 = new Aspose.Pdf.Generator.Text(section, r.ReadToEnd());
// enable the property to display HTML contents within their own formatting
text2.IsHtmlTagSupported = true;
//Add the text paragraphs containing HTML text to the section
section.Paragraphs.Add(text2);
// Specify the URL which serves as images database
pdf.HtmlInfo.ImgUrl = "D:/pdftest/MemoryStream/";
           
//Save the pdf document
pdf.Save("D:/pdftest/MemoryStream/HTML2pdf.pdf");

Copyright© 2006-2015 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 渝ICP备12000264号 法律顾问:元炳律师事务所
客服软件
live chat