Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to print PDF which is present in iframe?

I want to print pdf present in iframe.
I am able to print with browsers IE and Chrome, but it is giving problems with FireFox, Safari and Opera.

I have tried as follows:
C#
function printIframe() {
        if (navigator.userAgent.indexOf("Firefox") != -1) {
//This is not working
            var frame_window = window.frames["my_iframe"];
            frame_window.print();
                                  
        }
        else if (navigator.userAgent.indexOf("MSIE") != -1) {
//working
            var x = document.getElementById("pdfDocument");
            x.print();
        }
        else if (navigator.userAgent.indexOf("Chrome") != -1) {
//working
            document.my_iframe.focus();
            document.my_iframe.print();
        }
        else {
//not working
            // Safari browser or other one   
//            document.getElementById('my_iframe').focus();
//            document.getElementById('my_iframe').onload = setTimeout('iframe.print()',2500);
//            var ifWin = document.getElementById('my_iframe').contentWindow;
//            ifWin.focus();
//            ifWin.print();
            //printpdf();

        }

    }

Please guide me for this.

Thanks.
Posted
Updated 26-Jul-12 20:51pm
v3
Comments
carechin 8-Jul-14 1:30am    
Hi,
May I know how your IE working?
What is your component for "pdfDocument" ?
I have trouble on IE frame as well. Please help.

Thanks.

1 solution

This solution is for Java, but the principle should be possible to apply.

It addresses Safari and Chrome.
http://stackoverflow.com/questions/472951/how-do-i-print-an-iframe-from-javascript-in-safari-chrome[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900