[英]window.print() not applying the css while converting html to pdf
我在从 html 打印 pdf 时遇到问题,我正在使用 window.print() 函数但它没有应用 CSS,请有人帮我解决这个问题
这是我的代码,在这里我在第 3 行和第 4 行包含 CSS 文件,但这不起作用
CSS 在两到三个文件中,它是外部 css 而非内联,我尝试在这些文件中添加 @media 打印但没有用,让我知道我是否在下面的代码中正确引用了这些 css 文件,它是 reactjs 应用程序
let mywindow = window.open('', 'PRINT', 'height=650,width=900,top=100,left=150');
mywindow.document.write(`<html><head><title>test</title>`);
mywindow.document.write( `<link rel="stylesheet" href="style.css" type="text/css" media="print"/>` );
mywindow.document.write( `<link rel="stylesheet" href="App.css" type="text/css" media="print"/>` );
mywindow.document.write(`</head><body>`);
mywindow.document.write(document.getElementById("owtab").innerHTML);
mywindow.document.write(`</body></html>`);
mywindow.document.close();
mywindow.focus();
mywindow.print();
mywindow.close();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.