我正在使用HTML橋window.print()來打印20-30之間的範圍。 客戶說它正在打印空白頁。 我們只能在他們的機器上重現它。Silverlight HTML Bridge打印window.print()空白頁
這是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>
謝謝,我以某種方式通過在aspx頁面上使用iframe而不是從xaml中的window.print()使其不通過空白頁面進行打印。客戶端主要使用IE8。但我現在還有一個問題。當他們嘗試根據內容打印橫向廣告時,它會溢出到下一頁。任何關於如何使它適合瀏覽器上顯示的一頁的線索。我用CSS編輯了我的問題。 – user575219
是什麼意思是:如果內容溢出當前頁面框,是否有抑制分頁符的方法?我以這樣的方式構建我的表格,即每個頁面都有一個分頁符。目前在頁面中斷後的幫助下:始終,這可以正常工作。但是當內容溢出時它也會中斷。這隻發生在印刷風景 – user575219
謝謝你的幫助。做所有這些媒體查詢IE8的工作。你能指點我一些有用的鏈接IE8橫向 – user575219