title: How to print a pdf using javascript in jsp?
body: <p>I have an iframe, the contents of which are loaded from  jsp. The iframe contains a section in which i am showing a pdf . I have a button called print , which must let me print the pdf . This is the code that i have fished up after exploring stack :</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  function printPDF()
  {
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
  document.getElementById('PDFtoPrint').print();
  }
  else
  {
  var agreement = document.getElementById('PDFtoPrint');
  agreement.focus();
  agreement.contentWindow.print();
  } 
  }
  &lt;/script&gt;
  
  &lt;html&gt;
  &lt;object type="application/pdf" data="http://www.irs.gov/pub/irs-pdf/fw4.pdf" style="width:100%; height:100%" id="PDFtoPrint"&gt;
  &lt;/object&gt;
  &lt;a id="printbtn" href="#"  onclick="printPDF()"&gt;Print&lt;/a&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The problem is it is not working, either in mozilla or in chrome .
  This is the error that i keep getting :</p>
  
  <pre><code>Error: Error calling method on NPObject!
  agreement.focus();
  agreement.print();
  </code></pre>
  
  <p>Now , i know what NPobject is . But how can i overcome this problem ? What can i do here to make it work right ? </p>
  
  <p>Kindly help .</p>