2

I am able to use javascript to print PDF file in Internet Explorer and Firefox, as such:

<script type="text/javascript">
<!--
if (navigator.appName == 'Microsoft Internet Explorer')
{
    document.write('<object id="agreementPDF" type="application/pdf" data="file.pdf" width="100%" height="500"></object>');
}
else
{
    document.write('<iframe id="agreementFrame" src="file.pdf" width="100%" height="500px"></iframe>');
}
//-->
</script>

<script type="text/javascript">
<!--
function printAgreement()
{
    if (navigator.appName == 'Microsoft Internet Explorer')
    {
        document.getElementById('agreementPDF').print();
    }
    else
    {
        var agreement = document.getElementById('agreementFrame');
        agreement.focus();
        agreement.contentWindow.print();
    }   
}
//-->
</script>

<input type="button" name="print" onclick="printAgreement();" value="Print" />

However, in Opera, the print function does not work.

How do I make it work?

Thanks.

demongolem
  • 9,474
  • 36
  • 90
  • 105
akanevsky
  • 1,009
  • 2
  • 9
  • 18

2 Answers2

1

Looks like Opera needs a little more hand holding when it comes to the print dialog. Here are some very similar questions previously asked/answered on stackoverflow:

window.print not working with opera browser

print() not working on opera browser

Print iframe content in Opera and Chrome

Seems like you either need to use a different *.print() function or trigger the event after the page has finished loading.

Hope these links help.

Community
  • 1
  • 1
baraboom
  • 1,398
  • 9
  • 9
0

Have you tried printing on the window's onload event?

window.onload = function(){
  window.print();
};
Nick
  • 19,198
  • 51
  • 185
  • 312