Silverlight HTML Bridge打印window.print()空白页 [英] Silverlight HTML Bridge printing window.print() blank pages

查看:355
本文介绍了Silverlight HTML Bridge打印window.print()空白页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using HTML bridge window.print() to print range between 20-30. The client says it is printing blank pages. We can only reproduce it on their machine.

这是xaml中的代码,它将一个页面中的所有页面合并并打印。
此代码工作和打印所有页面。我们只需要在IE
我需要使用Windows 8和IE 10.但对于客户端,它打印一个空白页与页眉和页脚URL。

This is the code in xaml that combines all the pages in one page and prints it. This code works and prints all pages for me. We need this only on IE I am using windows 8 and IE 10. But for the client it prints one blank page with the header and footer url. It works correctly if he prints the current page or prints all the pages from start to end.

但是如果他尝试打印范围,23-30,它只打印23页-27左右。
有时它只打印一个空白页与页眉和页脚URL。不幸的是这些都没有发生在我的机器上。客户说他们在IE 8,IE 9和IE 11上尝试过。
可以建议我的选项是什么或者我可以注意的事情

But if he tries to print range, 23-30, it only prints 23-27 or so. Sometimes it prints just one blank page with the header and footer url. Unfortunately none of these happen on my machine. The client said that they tried it on IE 8, IE 9 and IE 11. Can some suggest what are my options or what are the things I could look out for

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来重现问题

There are a few things worth checking, as you have not provided enough CSS to reproduce the problem


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

  1. Firstly, this is a HTML problem, and has nothing to do with Silverlight. You should be able to generate a raw HTML file that reproduces the problem on the client site.

其次,您应该尝试打印到不同的纸张尺寸。美国A4尺寸略小于国际A4。

Secondly, you should try printing to different paper sizes. US A4 size is slightly shorter than international A4.

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

You should explore using CSS page break directive:

div#PAGE {page-break-after: always;}


  • 更新如果您希望支持页面方向,则可以使用媒体查询

  • Update If you wish to support page orientation, then you can use media queries in your CSS.

    @media print and (orientation: landscape) {
        /* landscape styles */
    }
    
    @media print and (orientation: portrait) {
        /* portrait styles */
        div#PAGE {page-break-after: always;}
    }
    


  • 必须支持(咳嗽) IE8 - 尝试polyfills。它们是提供IE8媒体查询支持的javascript库。请参见 respond.js 或< a href =https://modernizr.com/ =nofollow> modernizr 。

  • Since our poor developer still has to support (cough cough) IE8 - try out polyfills. They are javascript libraries that give IE8 media query support. See respond.js or modernizr.

    这篇关于Silverlight HTML Bridge打印window.print()空白页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆