Silverlight HTML Bridge 打印 window.print() 空白页

2024-01-25

我正在使用 HTML 桥 window.print() 打印 20-30 之间的范围。 客户说正在打印空白页。 我们只能在他们的机器上重现它。

这是 xaml 中的代码,它将所有页面合并到一页中并打印它。 这段代码可以工作并为我打印所有页面。我们只在 IE 上需要这个 我使用的是 Windows 8 和 IE 10。但对于客户端,它会打印一张带有页眉和页脚 URL 的空白页。如果他打印当前页面或打印从头到尾的所有页面,则它工作正常。

但如果他尝试打印范围 23-30,它只会打印 23-27 左右。 有时它只打印一张带有页眉和页脚 URL 的空白页。不幸的是,这些都没有发生在我的机器上。客户表示他们在IE 8、IE 9和IE 11上进行了尝试。 有人可以建议我有什么选择或者我可以注意什么

Page.xaml.cs


       Dictionary<int, List<string>> AllPages = new Dictionary<int, List<string>>();
        --code to add to AllPages
   // Load all pages onto page
             for (int Page = startPage; Page <= endPage; Page++)
                            {
                                if (AllPages.ContainsKey(Page))
                                {

                                    List<string> PageLines = AllPages[Page];
                                    this.m_Div = this.m_HtmlDoc.CreateElement("DIV");
                                    if (Page != AllPages.Count)
                                    {
                                        this.m_Div.SetAttribute("ID", "Page");
                                    }
                                    this.m_Table = this.m_HtmlDoc.CreateElement("TABLE");
                                    this.m_Div.AppendChild(this.m_Table);

                                    for (int Line = 0; Line < PageLines.Count; Line++)
                                    {
                                        this.m_TR = this.m_HtmlDoc.CreateElement("TR");
                                        this.m_TD = this.m_HtmlDoc.CreateElement("TD");
                                        this.m_TD.SetProperty("innerText", PageLines[Line]);
                                        this.m_TR.AppendChild(this.m_TD);
                                        this.m_Table.AppendChild(this.m_TR);
                                    }
                                    this.m_PrintReport.AppendChild(this.m_Div);
                                }
                            }

      HtmlPage.Window.Invoke("printfunction", m_PrintReport);

CSS

body
{
    background:#ffffff;
    color:#000000;
    font-family: rvConsolas;
     margin: 0px;  /* the margin on the content before printing */
     width:100%;
     height:100%;
     background-color:#DDD;
     min-height:100%;

}

html{
    width:100%;
    height:100%;
}

@font-face
{
    font-family: rvConsolas;
    font-style: normal;
    font-weight: normal;
    src: url(EmConsola.eot);
    src: url('EmConsola.eot?#iefix') format('embedded-opentype')
}

 @page 
        {
            size: auto;   /* auto is the current printer page size */
            margin: 0mm;  /* this affects the margin in the printer settings */

        }


#rptViewer 
{
    display: none;
    visibility: hidden;
}

#printReport
{
    visibility: visible;
    font-family: rvConsolas;
    overflow: hidden;
     display:inline-block;
}

td 
{
    font-family: rvConsolas;
    overflow:visible;
    font-size: 52%;
    display:block;
}

#Page
{

    page-break-after: always;


}

ASPX 页面

     <link href="Style/style.css" rel="Stylesheet" media="screen" />
        <link href="Style/print.css"  type="text/css" rel="Stylesheet" media="print" />
        <script src="Scripts/Silverlight.js" type="text/javascript"></script>

        <script type="text/javascript">

            function init() {
                printReport.style.display = false;
            }
            function onSLLoad(plugIn, userContext, sender) {
                alert("silverlight");
                window.status +=
                    plugIn.id + " loaded into " + userContext + ". ";
            }

            function printfunction(arg) {
                var contents = arg.innerHTML;
                var frame1 = document.createElement('iframe');
                frame1.name = "frame1";

                frame1.style.position = "absolute";
                frame1.style.top = "-1000000px";
                document.body.appendChild(frame1);
                var frameDoc = (frame1.contentWindow) ? frame1.contentWindow : (frame1.contentDocument.document) ? frame1.contentDocument.document : frame1.contentDocument;
                frameDoc.document.open();
                frameDoc.document.write('<html><head>');
                frameDoc.document.write('</head><body>');
                var path = "Style";
                var style = document.createElement('link');
                style.rel = 'stylesheet';
                style.type = 'text/css';
                style.href = path + '/print.css';
                frameDoc.document.getElementsByTagName('head')[0].appendChild(style);
                frameDoc.document.write(contents);
                frameDoc.document.write('</body></html>');
                frameDoc.document.close();
                setTimeout(function () {
                    frame1.contentWindow.focus();
                    frame1.contentWindow.print();
                    document.body.removeChild(frame1);
                },1000);
            }
        </script>     
    </head>
<body>
    <div id="printReport" style ="
                white-space: nowrap;   ">


    </div>
</body>

有一些事情值得检查,因为您没有提供足够的 CSS 来重现问题

  1. 首先,这是一个 HTML 问题,与 Silverlight 无关。您应该能够生成一个原始 HTML 文件,在客户端站点上重现问题。

  2. 其次,您应该尝试打印到不同的纸张尺寸。美国 A4 尺寸比国际 A4 稍短。

  3. 您应该探索使用 CSS 分页符指令:

    div#PAGE {page-break-after: always;}
    
  4. Update如果您想支持页面方向,那么您可以使用媒体查询 https://stackoverflow.com/questions/16596982/media-queries-for-landscape-printing在你的 CSS 中。

    @media print and (orientation: landscape) {
        /* landscape styles */
    }
    
    @media print and (orientation: portrait) {
        /* portrait styles */
        div#PAGE {page-break-after: always;}
    }
    
  5. 既然我们可怜的开发者还得支持(咳咳)IE8- 尝试填充。它们是提供 IE8 媒体查询支持的 JavaScript 库。看响应.js http://voceplatforms.com/2014/07/5-tools-that-make-ie8-development-suck-less/ or 现代化 https://modernizr.com/.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Silverlight HTML Bridge 打印 window.print() 空白页 的相关文章