Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

361
Views
Is there any alternative to window.open to print a PDF? (dialog to print the PDF)

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

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!