我想在Angular 4中打印整个页面,并且我将下面的代码用于同一页面。但是我必须单独编写CSS。
_PrintReceipt = async () => {
let printContents, popupWin;
printContents = document.getElementById('print-section').innerHTML;
popupWin = window.open('', '_blank', 'top=0,left=0,height=100%,width=auto');
popupWin.document.open();
popupWin.document.write(`
<html>
<head>
<title>Receipt</title>
<style>
.print-section {
margin: 2%;
}
...........
</style>
</head>
<body onload="window.print();window.close()"><div class="print-
section">${printContents}</div></body>
</html>`
);
popupWin.document.close();
}
是否可以按原样打印html页面?