I'm interested in efficiently printing multiple custom HTML invoices with just one click, similar to this example:
https://i.sstatic.net/hAQgv.png
Although I attempted to achieve this functionality using the following method, it appears to be incorrect as it prompts the print dialog multiple times:
printInvoices() {
this.orders.forEach(order => {
let content = `
<head>
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="395b56564d4a4d4b4b2f6669666562612763040c55010104063e">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
<style>
@media print {
.invoice {
font-size: 11px !important;
overflow: hidden !important
}
}
</style>
</head>
<body>
—
</body>
`;
let newWindow = window.open("", "", "width=300,height=300");
newWindow?.document.write(content);
newWindow?.focus();
newWindow?.print();
newWindow?.close();
});
}
Any suggestions on how to accomplish this task more effectively?