ITextSharp HTML转换为PDF?

我想知道ITextSharp是否具有将HTML转换为PDF的功能。我将转换的所有内容都只是纯文本,但是不幸的是,关于ITextSharp的文档很少甚至没有文档,因此我无法确定这是否对我来说是可行的解决方案。


如果做不到,是否有人可以将一些简单的纯文本HTML文档转换为pdf的良好,免费的.net库指向我?


tia。


慕慕森
浏览 402回答 3
3回答

慕村225694

在进行了一些挖掘之后,我找到了一种很好的方式来实现ITextSharp所需的功能。这是一些示例代码,如果将来会帮助其他人:protected void Page_Load(object sender, EventArgs e){&nbsp; &nbsp; Document document = new Document();&nbsp; &nbsp; try&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; PdfWriter.GetInstance(document, new FileStream("c:\\my.pdf", FileMode.Create));&nbsp; &nbsp; &nbsp; &nbsp; document.Open();&nbsp; &nbsp; &nbsp; &nbsp; WebClient wc = new WebClient();&nbsp; &nbsp; &nbsp; &nbsp; string htmlText = wc.DownloadString("http://localhost:59500/my.html");&nbsp; &nbsp; &nbsp; &nbsp; Response.Write(htmlText);&nbsp; &nbsp; &nbsp; &nbsp; List<IElement> htmlarraylist = HTMLWorker.ParseToList(new StringReader(htmlText), null);&nbsp; &nbsp; &nbsp; &nbsp; for (int k = 0; k < htmlarraylist.Count; k++)&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; document.Add((IElement)htmlarraylist[k]);&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; document.Close();&nbsp; &nbsp; }&nbsp; &nbsp; catch&nbsp; &nbsp; {&nbsp; &nbsp; }}
打开App,查看更多内容
随时随地看视频慕课网APP