重现代码
const iframe = document.createElement('iframe');
iframe.onload = () => {
iframe.focus();
iframe.contentWindow.print();
}
iframe.src="path/to/pdf/file"
解决方法
const iframe = document.createElement('iframe');
iframe.onload = () => {
setTimeout(() => {
iframe.focus();
iframe.contentWindow.print();
}, 1000);
}
iframe.src="path/to/pdf/file"