我一直在使用 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();
}
最佳答案
关于asp.net - 将 HTML 转换为 PDF 时如何保留外观,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/731949/