代码之家  ›  专栏  ›  技术社区  ›  SomeStudent

iTextSharp LGPLv2.Core未能在<style>标记中正确应用CSS

  •  0
  • SomeStudent  · 技术社区  · 6 年前

    我遇到了一个问题,我的itextsharp似乎无法正确地解析和应用非内联样式到我的HTML,相反,它只在内联样式正确的情况下呈现PDF,但它将中的任何内容都视为常规字符串。

    经过一些研究,我发现它有一个样式表类,所以我决定删除标记中的css,并尝试将其添加到页面中,如下所示:

    var css = new StyleSheet();
                    css.LoadStyle("h1", "text-align", "center");
                    css.LoadStyle("h1", "text-transform", "uppercase");
                    css.LoadStyle("h1", "text-align", "center");
    
                    css.LoadStyle("h2", "text-align", "center");
                    css.LoadStyle("h2", "text-transform", "uppercase");
                    css.LoadStyle("h2", "text-align", "center");
    
                    css.LoadStyle("h3", "text-align", "center");
                    css.LoadStyle("h3", "text-transform", "uppercase");
                    css.LoadStyle("h3", "text-align", "center");
    
                    css.LoadStyle("marginBottomSmall", "margin-bottom", "10px");
                    css.LoadStyle("tableTopAlign", "vertical-align", "top");
    
                    css.LoadStyle("customBullet::before", "content", @"'\2022'");
                    css.LoadStyle("customBullet::before", "padding-right", "0.5em");
    
                    css.LoadStyle("customBullet", "display", "flex");
    
                    css.LoadStyle("flexColumnContainer", "display", "flex");
                    css.LoadStyle("flexColumnContainer", "flex-direction", "column");
    
                    css.LoadStyle("tableDiv", "display", "table");
    
                    css.LoadStyle("fixedWidthMed", "width", "325px");
                    css.LoadStyle("fixedWidthMed", "display", "table-cell");
    
                    css.LoadStyle("tableRow", "display", "table-row");
    
                    css.LoadStyle("flexRowContainer", "display", "flex");
                    css.LoadStyle("flexRowContainer", "flex-direction", "row");
    
                    css.LoadStyle("forceULPadding", "padding-left", "20px");
    
                    css.LoadStyle("SoapListNoBullets", "list-style", "none");
    
                    css.LoadStyle("printable", "max-width", "800px");
    
                    css.LoadStyle("bottomPadContent td", "padding-bottom", "10px");
                    css.LoadStyle("bottomPadContent td", "vertical-align", "top");
    

                var htmlWorker = new HtmlWorker(doc);
                htmlWorker.Style = css;
    

    0 回复  |  直到 6 年前
    推荐文章