經過大量的研究最終得到它使用iframe。此代碼非常有幫助http://www.sitepoint.com/load-pdf-iframe-call-print/ 我的視圖中有一個空的隱藏iframe。 這是鉻,FF,但不是在IE中工作
Search.openPrintDialog = function() {
var printJobIds = $("input:checkbox[name='Print']:checked").map(function() { return this.value; }).get().join(',');
if (printJobIds.length > 0)
{
JSUtil.BlockUI();
print('/' + JSUtil.GetWebSiteName() + '/Search/LoadDownloadAndPrint?Print=' + printJobIds)
}
return false;
}
function print(url) {
var _this = this,
iframeId = 'iframeprint',
$iframe = $('iframe#iframeprint');
$iframe.attr('src', url);
$iframe.load(function() {
_this.callPrint(iframeId);
});
}
//initiates print once content has been loaded into iframe
function callPrint(iframeId) {
var PDF = document.getElementById(iframeId);
PDF.focus();
PDF.contentWindow.print();
JSUtil.UnBlockUI();
}