Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: PDF
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:
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 26-Jul-12 21:24pm
Edited 26-Jul-12 21:51pm
v3
Comments
carechin at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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[^]
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 200
1 George Jonsson 175
2 Kornfeld Eliyahu Peter 169
3 PIEBALDconsult 110
4 Richard MacCutchan 85
0 OriginalGriff 6,080
1 DamithSL 4,648
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,624
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 8 Jul 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100