我需要在Angular +2中使用div
打印ngx-print
,但要手动发送,而不是作为按钮属性ngxPrint
<button printSectionId="print-section" (click)="printProcedure()">print</button>
printProcedure(){
/* DO SOME STUFF*/
//Print out after validations
ngxPrint.print()
}
答案 0 :(得分:0)
您不需要使用ngx-print pack。您只能使用这样的JS来做到这一点。
printProcedure(innerHtml: any) {
const mywindow = window.open('', 'PRINT', 'width=1023,height=1000');
mywindow.document.write(`
<html>
<head>
<link rel="stylesheet" type="text/css" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.0/css/bootstrap.min.css">
<style type="text/css">
@page {
page-break-after: always;
margin: 2cm 1cm;
}
pre {
font-size: 20px;
border: 0;
margin-top: -130px;
}
</style>
</head>
<body>${innerHTML}</body>
</html>`);
mywindow.document.close();
mywindow.focus();
setTimeout(() => {
mywindow.print();
mywindow.close();
}, 400);
}