当将embed标签用于pdf时,为什么在打印屏幕上会出现空白页?

时间:2018-12-23 13:52:40

标签: javascript html pdf printing embed

我想使用嵌入标签打印PDF。 PDF出现在屏幕上,但空白页面出现在打印屏幕上。为什么?以及我该如何解决?

const width = window.innerWidth * 0.9;
const height = window.innerHeight * 0.9;
const content = `<!DOCTYPE html>
        <html>
        <head><title></title></head>
        <body onload="window.focus(); window.print(); window.close();">
        <embed width="720" height="540" src="https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf" />
        </body>
        </html>`;
const options = 'toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes,width=' + width + ',height=' + height;
const printWindow = window.open('', 'print', options);
printWindow.document.open();
printWindow.document.write(content);
printWindow.document.close();
printWindow.focus();

0 个答案:

没有答案