asp.net - 将 HTML 转换为 PDF 时如何保留外观

标签 asp.net itext pdf-generation

我一直在使用 iTextSharp 进行 HTML 到 PDF 的转换,总体来说它工作得相当好,但它似乎不像大多数格式。

粗体、斜体和下划线都可以使用,但是,没有考虑任何字体大小、样式或其他信息,因此导出的内容看起来与用于创建格式的 HTML 完全不同。

有谁知道怎么做吗

  • 修复 iTextSharp 导出的方式(下面是我的代码示例)
  • 或者知道有其他产品可以提供此功能,而且不会花很多钱吗?

这是我的代码:

//Do the PDF thing
Document document = new Document(PageSize.A4);
using (Stream output = new FileStream(Server.MapPath(relDownloadDoc), FileMode.Create, FileAccess.Write, FileShare.None))
using (Stream htmlStream = new FileStream(Server.MapPath(relProcessingDoc), FileMode.Open, FileAccess.Read, FileShare.Read))
using (XmlTextReader reader = new XmlTextReader(htmlStream))
{
    reader.WhitespaceHandling = WhitespaceHandling.None;
    PdfWriter.GetInstance(document, output);
    document.Open();
    Console.ReadLine();
    HtmlParser.Parse(document, reader);
    document.Close();
}

最佳答案

尝试 WKHTMLTOPDF。

它是 webkit 的开源实现。两者都是免费的。

我们设置了一个小教程here

关于asp.net - 将 HTML 转换为 PDF 时如何保留外观,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/731949/

相关文章:

java - 将 PDFStampers 中的两个 pdf 内存流合并为一个带 2 页的内存流

c# - Linq-to-SQL WHERE IN 语句返回的内容超出预期

c# - GridView 不可见行显示在空数据行中

c# - updatePanel 不在单选按钮上刷新

c# - JSON Post 我的 .NET MVC 2 Controller 需要什么参数

ios - 是否可以使用 UIKit 创建 PDF 表单

java - iText 不添加一行表格

java - PdfReader无法解析为类型

ruby - 在 Ruby/Rails 中将 Word 转换为 PDF?

c# - Itext 7 - PdfReader 未使用所有者密码错误打开