[英]JS Print pdf file
I try to print pdf file in javaScript. 我尝试在javaScript中打印pdf文件。 I get the file's url from the server. 我从服务器获取文件的URL。
var iframe = document.createElement('iframe');
document.body.appendChild(iframe);
iframe.style.display = 'none';
iframe.src = urlBaseImage + 'Report//' + result;
iframe.focus();
iframe.contentWindow.print();
But he give me empty page, I checked the url and it is really correct. 但他给我空页,我检查了网址,这是非常正确的。 What Can I do? 我能做什么? Thanks! 谢谢!
You can use this library, Print.js: http://printjs.crabbly.com/ 您可以使用此库Print.js: http ://printjs.crabbly.com/
It is very easy to print PDF files with it. 用它打印PDF文件非常容易。
Just pass the PDF file url to the printJS()
function; 只需将PDF文件URL传递给printJS()
函数;
For example: 例如:
printJS('docs/my_pdf_file.pdf');
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);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.