1

在我的 aspx 页面中,我有这个带有以下 css 的脚本

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

在浏览器中,页面加载正常,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();

我见过很多这样的问题,但我还没有找到答案

如何在文档中添加 css 样式?

4

1 回答 1

1

既然您指定 theDoc2.HtmlOptions.Media = MediaType.Print;了,您是否尝试过标记您的 css for @media print

像这样:

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

或者,取出线路theDoc2.HtmlOptions.Media = MediaType.Print;

我还没有验证这一点,但值得一试。

于 2014-09-10T23:45:06.777 回答