【问题标题】:How to convert HTML into PDF using iTextSharp in winform?如何在 winform 中使用 iTextSharp 将 HTML 转换为 PDF?
【发布时间】:2014-12-05 13:11:00
【问题描述】:

我想以 Windows 形式将 HTML 转换为 PDF。我在网上看到了很多很棒的文章,例如:

但它们并不能完全解决我的问题。

我可以只传递一个 HTML 字符串并在 Winform 中将其转换为 PDF 吗?

例如:

string html = "<table><tr><td>Arbaaz</td><tr></table>"

我可以将此字符串传递给某些 iText 方法来创建 PDF 吗?

【问题讨论】:

标签: c# html winforms pdf itextsharp


【解决方案1】:

在这里找到了我想要的答案..

Document document = new Document();
PdfWriter.GetInstance(document, new FileStream(Request.PhysicalApplicationPath + "\\MySamplePDF.pdf", FileMode.Create));
document.Open();
iTextSharp.text.html.simpleparser.HTMLWorker hw = 
             new iTextSharp.text.html.simpleparser.HTMLWorker(document);
hw.Parse(new StringReader(htmlText));
document.Close();

https://stackoverflow.com/a/18378661/2064292

【讨论】:

    猜你喜欢
    • 2014-09-29
    • 2022-03-07
    • 1970-01-01
    • 2016-07-08
    • 1970-01-01
    • 2013-05-07
    • 1970-01-01
    相关资源
    最近更新 更多