我试着用javaScript打印pdf文件。我从服务器获取文件的url。
var iframe = document.createElement('iframe');
document.body.appendChild(iframe);
iframe.style.display = 'none';
iframe.src = urlBaseImage + 'Report//' + result;
iframe.focus();
iframe.contentWindow.print();
但他给我的页面是空的,我检查了网址,它确实是正确的。我能做什么?谢谢!
发布于 2016-04-16 01:18:09
您可以使用这个库,Print.js:http://printjs.crabbly.com/
这是非常容易打印PDF文件与它。
只需将PDF文件url传递给printJS()
函数即可;
例如:
printJS('docs/my_pdf_file.pdf');
发布于 2016-06-15 23:47:14
function printDisclosureDocument() {
var doc = document.getElementById('pdfDocument');
if (doc == 'undefined' || doc == null) {
var pdfbox = document.createElement('embed');
pdfbox.type = 'application/pdf';
pdfbox.src = 'ShowPDF.aspx?refid=' + $('#MainContent_hdnRefId').val();
pdfbox.width = '1';
pdfbox.height = '1';
pdfbox.id = 'pdfDocument';
document.body.appendChild(pdfbox);
}
if (doc != null && doc != 'undefined') {
//Wait until PDF is ready to print
if (typeof doc.print === 'undefined') {
setTimeout(function () { printDisclosureDocument(); }, 500);
} else {
doc.print();
}
}
else {
setTimeout(function () { printDisclosureDocument(); }, 500);
}
}
https://stackoverflow.com/questions/35333256
复制相似问题