【问题标题】:Style is not going to apply to pdf after converting From html string从 html 字符串转换后,样式不会应用于 pdf
【发布时间】:2011-06-14 11:31:28
【问题描述】:

我正在使用以下代码。但是课堂上提到的风格不适用于pdf。为什么?这段代码有什么问题。

Document document = new Document(PageSize.A4, 0, 0, 30, 65);
                PdfWriter.GetInstance(document, new FileStream(Server.MapPath("/") + "Temp/" + "parsetest11.pdf", FileMode.Create));
                document.Open();
                string htmlTabel = "<table width='660' border='0' cellspacing='0' cellpadding='05' class='myclass'><tr><td>Welcome</td></tr></table>";
                StringReader abc = new StringReader(htmlTabel);
                iTextSharp.text.html.simpleparser.StyleSheet styles = new iTextSharp.text.html.simpleparser.StyleSheet();
                styles.LoadStyle("myclass", "clspdf", "color:red; font-family:Arial, Helvetica, sans-serif; font-size:16px; padding:7px; font-weight:bold;");// Not working
                List<iTextSharp.text.IElement> elements = iTextSharp.text.html.simpleparser.HTMLWorker.ParseToList(abc, styles);
                foreach (object item in elements)
                {
                    document.Add((IElement)item);
                }
                document.Close();

【问题讨论】:

    标签: asp.net pdf itext


    【解决方案1】:

    iText 的 CSS 支持参差不齐,但越来越好。您是否尝试过最新版本:5.1.1?

    在完成任务之前,我建议您查看 WKHTML2PDF,这是一个基于 WebKit 的命令行实用程序。非常好。

    【讨论】:

    • 您好 Mark Storer 感谢您的回复。我如何在 C# 中使用 WKHTML2PDF?
    • 我用谷歌搜索了“asp 命令行”。前 3-4 次点击都告诉我如何从 ASP 运行命令行应用程序。下次试试
    猜你喜欢
    • 2019-07-21
    • 2023-03-13
    • 2016-10-10
    • 1970-01-01
    • 1970-01-01
    • 2016-07-19
    • 2011-01-15
    • 1970-01-01
    • 2017-12-25
    相关资源
    最近更新 更多