简体   繁体   English

ABCpdf不应用内联CSS样式

[英]ABCpdf not applying inline css styles

In my aspx page I have this script with the following css 在我的aspx页面中,我具有以下CSS的脚本

<style type="text/css">
        .subcontainer{margin: 0 auto; padding-top: 20px}
       .hide-val{display:none;}
    </style>

In the browser the page is loads ok, div with class hide-val is not displayed but when I use AddImageURL styles is not being applied. 在浏览器中,页面加载正常,没有显示带有hide-val类的div,但是当我使用AddImageURL样式时,未应用。

Doc theDoc2 = new Doc();

            theDoc2.HtmlOptions.UseScript = true;
            theDoc2.HtmlOptions.Media = MediaType.Print;
            theDoc2.HtmlOptions.InitialWidth = 1048;

            //for multiple page
            theDoc2.Rect.Inset(10, 30);

            theDoc2.Page = theDoc2.AddPage();
            int theID2;
            theID2 = theDoc2.AddImageUrl(urlToHtmlPage);

            while (true)
            {
                theDoc2.FrameRect(); // add a black border
                if (!theDoc2.Chainable(theID2))
                    break;
                theDoc2.Page = theDoc2.AddPage();
                theID2 = theDoc2.AddImageToChain(theID2);
            }

            for (int i = 1; i <= theDoc2.PageCount; i++)
            {
                theDoc2.PageNumber = i;
                theDoc2.Flatten();
            }
            //end multipage 
            theDoc2.Save(HttpContext.Current.Server.MapPath("htmlimport.pdf"));
            theDoc2.Clear();

I have seen many questions like this but I haven't found the answer 我已经看到很多类似的问题,但是我没有找到答案

How can I add the css style in the doc? 如何在文档中添加CSS样式?

Since you specified theDoc2.HtmlOptions.Media = MediaType.Print; 由于您指定了theDoc2.HtmlOptions.Media = MediaType.Print; , have you tried marking your css for @media print ? ,您是否尝试过将CSS标记为@media print

Like so: 像这样:

<style type="text/css">
  @media print {
       .subcontainer{margin: 0 auto; padding-top: 20px}
       .hide-val{display:none;}
  }
</style>

Alternatively, take out the line theDoc2.HtmlOptions.Media = MediaType.Print; 或者,取出theDoc2.HtmlOptions.Media = MediaType.Print;theDoc2.HtmlOptions.Media = MediaType.Print;

I haven't verified this, but it's worth a shot. 我尚未证实这一点,但值得一试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM