如何在angular4中打印整个HTML页面

时间:2018-07-18 04:33:39

标签: angular

我想在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页面?

1 个答案:

答案 0 :(得分:0)

您可以使用JavaScript window.print() method