0

I have created the print function that is working fine in chrome but in firefox its printing blank page. because print dialog comes before the PDF fully loaded so when we hit "ok" its perform the action to print. Question is how to add delay to print dialog to appear after PDF fully Loaded.

Here is My Code:

   function printPDF(url) 
    {

    var w = window.open(url);

   var FIREFOX = /Firefox/i.test(navigator.userAgent);
    if (FIREFOX) {
    if (typeof w.print === 'undefined') {    
    setTimeout(function(){printPDF(url);},3000);
    } else {
     w.print();
    }

     }else{

      w.print();
       }
   }
Xabby
  • 435
  • 6
  • 26
  • What is your question? What are you getting as an error message? – T0xicCode Mar 30 '16 at 19:59
  • @T0xicCode Actually I have multiple PDF documents on this page each have print option beneath it but when i try to print its give me black page not the actual PDF: http://drnullman.mxcounters.com/?page_id=2505 – Xabby Mar 31 '16 at 10:27
  • maybe you can open it as popup then print. – Kamuran Sönecek Mar 31 '16 at 10:31
  • I have already done that thing but now the requirement is to print the document directly from the button: here is the example i done before: @Kamuran Sönecek – Xabby Mar 31 '16 at 10:33

1 Answers1

0

I suspect you are getting a blank page because your window 'w' contains no printable text. The PDF is opened via a plugin which falls outside your w.print(); request.

var w = window.open(url);
w.print();

I suspect your options are limited - the plugin opens the PDF - a different plugin could have a different js library so a universal solution might not be available.

  • So What is the best practice to do such tasks do you have any alternate: @fiprojects – Xabby Mar 31 '16 at 10:49
  • Sorry but I have no idea - I have never have combined javascript and PDFs... Have you tried: http://stackoverflow.com/questions/16239513/print-pdf-directly-from-javascript –  Mar 31 '16 at 13:14