I have to open a PDF and ask to print it automatically. I did this:
const pdfWindow = window.open("generate_pdf.php?id="+id, "_blank");
if (!pdfWindow) {
alert("You have to enable popups");
} else {
pdfWindow.addEventListener("load", function () {
pdfWindow.print();
}, false);
}
this is working correctly, window.open opens the link that output the PDF, then when the page loaded, it calls pdfWindow.print(); that open the dialog to print the PDF.
The problem is that browsers default have popup disabled. So most users will see "You have to enable popups" alert, because window.open will fails. I know popups can be easily enabled, but this is not nice for most users :(
Is there an other solution instead of window.open to: Open "generate_pdf.php". Then, when "generate_pdf.php" generated the PDF, automatically ask to print it.
I used window.open because user should to remain on the main page.
Edit: The reason why I have to automatically open the print dialog is because I want to be sure that operators will not forget to print the PDF