iTextSharp的HTML到PDF? [英] ITextSharp HTML to PDF?
问题描述
我想知道,如果iTextSharp的有将HTML转换为PDF格式的功能。一切我会转换也只是普通的文本,但可惜的是很少的iTextSharp的任何文件,所以我不能确定,这将是对我来说是可行的解决方案。
I'd like to know if ITextSharp has the capability of converting HTML to PDF. Everything I will convert will just be plain text but unfortunately there is very little to no documentation on ITextSharp so I can't determine if that will be a viable solution for me.
如果不能做到这一点,可有人点我一些很好的,免费的.NET库,可以采取一个简单的纯文本的HTML文档,并将其转换为PDF格式?
If it can't do it, can someone point me to some good, free .net libraries that can take a simple plain text HTML document and convert it to a pdf?
TIA。
推荐答案
在做一些挖后,我发现了一个很好的方式来完成我需要用iTextSharp的。
after doing some digging I found a good way to accomplish what I need with ITextSharp.
下面是一些示例code。如果这将有助于其他人在未来的:
Here is some sample code if it will help anyone else in the future:
protected void Page_Load(object sender, EventArgs e)
{
Document document = new Document();
try
{
PdfWriter.GetInstance(document, new FileStream("c:\\my.pdf", FileMode.Create));
document.Open();
WebClient wc = new WebClient();
string htmlText = wc.DownloadString("http://localhost:59500/my.html");
Response.Write(htmlText);
List<IElement> htmlarraylist = HTMLWorker.ParseToList(new StringReader(htmlText), null);
for (int k = 0; k < htmlarraylist.Count; k++)
{
document.Add((IElement)htmlarraylist[k]);
}
document.Close();
}
catch
{
}
}
这篇关于iTextSharp的HTML到PDF?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!