mhk
mhk

Reputation: 434

printing a pdf opened in iframe sourced by google doc viewer by javascript

is it possible to print pdf opened in iframe sourced by google doc viewer by javascript... ? for some reason i want the user to be on same page and print the pdf from same page...

here's the code of iframe:

<button style="height:35px; cursor:pointer; " class="button" id="print"> <img src="images/print.png"/> <span style=" vertical-align: super; "> Print this note </span> </button>   
<?php echo '<iframe id="PDFtoPrint" src="http://docs.google.com/gview?url='.JURI::root().'resources/pdf_full/'.$full_name.'&embedded=true" style="width:800px; height:1000px; " frameborder="0"></iframe>';?>

and here's the jquery code from printing...

 jQuery(document).ready(function($) {

    $('#print').click(function(){
        // window.frames["PDFtoPrint"].focus();
        // window.frames["PDFtoPrint"].print();    // NOT WORKING

        // var PDF = document.getElementById('PDFtoPrint');
        // PDF.focus();
        // PDF.contentWindow.print();              // NOT WORKING

        // $("#PDFtoPrint").get(0).contentWindow.print();  // NOT WORKING

        // document.getElementById("PDFtoPrint").contentWindow.print(); // NOT WORKING


    });
 });

Upvotes: 1

Views: 1480

Answers (1)

aecend
aecend

Reputation: 2462

No, this isn't possible due to JavaScript's Same Origin Policy. JavaScript isn't able to manipulate or otherwise interact with the DOM of a page loaded in a frame from another domain. There is one exception as far as I know, but that would require that Google explicitly allow your site to do so, which they won't. You can read more about the Same Origin Policy here: https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy

Upvotes: 1

Related Questions