1.首先获取到当前PDF文件的链接
2.在放JS的文件包里面创建一个common.js文件,写入要实现功能的代码。
// 调用打印弹框
function dialogPoint(urlAdd){
fetch(urlAdd).then(res => res.blob()).then(blob => {
var date = (new Date()).getTime()
var ifr = document.createElement('iframe')
ifr.style.frameborder = 'no'
ifr.style.display = 'none'
ifr.style.pageBreakBefore = 'always'
ifr.setAttribute('id', 'printPdf' + date)
ifr.setAttribute('name', 'printPdf' + date)
ifr.src = window.URL.createObjectURL(blob);
document.body.appendChild(ifr)
doPrint('printPdf' + date)
});
}
function doPrint(val) {
var ordonnance = document.getElementById(val).contentWindow
setTimeout(() => {
ordonnance.print()
}, 100)
}
export {
dialogPoint,
}
3.在需要实现打印弹框功能的页面导入使用就可以实现以下效果了。