Skip navigation
Currently Being Moderated

Print a PDF from an iFrame, Reader X

Oct 6, 2011 8:04 AM

Tags: #iframe #safari #firefox #print #reader_x

Firefox versions 4 and up and also Safari, with Adobe Acrobat Reader, are conspiring not to print the PDF content of an iframe's contentwindow.

 

I have a HTML page with Javascript. There is an iFrame and an input type button on this page. The iFrame src tag points to a PDF.

 

I am using FireFox 7 here, so I get access to the window onafterprint event. (There's talk that FF6 has it too; and FF8 beta has it.) Also I am on Windows 7, 64 bit. The version of the Reader is "X", 10.1.1; the same happens with 8.3 and 9.4.

 

<html>

<body>

<input id="btnPrint1" type="button" onclick="printPdfFirefox()" value="print" />

 

<iframe id="ifrmPDF" src="twopage.pdf"></iframe>

 

<br><hr><br>

 

<input id="btnPrint2" type="button" onclick="printTextFirefox()" value="print" />

 

<iframe id="ifrmText" src="text.txt"></iframe>

 

 

<script>

 

function printPdfFirefox()

{

iframe = document.getElementById("ifrmPDF");

 

iframe.contentWindow.onafterprint = function (evt)

{

alert('i just printed something');

};

iframe.focus();

iframe.contentWindow.print();

}

 

 

 

function printTextFirefox()

{

iframe = document.getElementById("ifrmText");

 

iframe.contentWindow.onafterprint = function (evt)

{

alert('i just printed something');

};

iframe.focus();

iframe.contentWindow.print();

}

</script>

</body>

</html>

 

Firefox successfully loads the PDF into the iFrame. The input button then calls the print method of the iFrame, and (in FF7+) the (content)window fires the event.

 

What doesn't happen is printing. Reader X is refusing such calls from FF4+ (I verified earlier versions with a VM). Safari will print a blank page. I can verify that Reader does let FF 3.6 print. I can also verify that FF4+ and Safari have no problem with printing a text file.

 

[Chrome prints; but Chrome seems to be using an independent process and not your Reader.]

 

And I can print this PDF from other parts of the system; as long as I stick to serving it up as a full PDF and don't embed it in an iFrame.

 

I monkeyed with the security settings in Adobe Reader for a bit, but this was voodoo and didn't help. Is there some way of telling what Reader's thought process was, when it didn't print the document but also didn't raise an exception? I don't know how to get access to Reader X's properties, from external javascript. Nor the document's properties.

 

I would really like an answer to why this is going on. Thanks!

 
Replies
  • Currently Being Moderated
    Mar 23, 2012 10:42 AM   in reply to d_ross

    Has there been a fix or at least cause suggested for this?  I can get the pdf print dialog to show with earlier versions of the reader but upgrading to reader X causes a strange silence when the javascript print button is pressed.  Just curious if there is any word on how to fix this.  I would appreciate any help that can be provided.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 23, 2012 2:24 PM   in reply to d_ross

    I am a bit confused as to why you would be using the web browser's JavaScript API and not Adobe Reader's JavaScript API to print the PDF file?

    The Acrobat SDK has information about doing this via the ActiveX control.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 23, 2012 2:41 PM   in reply to Sabian Zildjian

    Sabian,

     

    Because that is how the website was coded when I was assigned the investigation.  Things worked fine up to the point that Reader X was deployed and then they broke.  I am aware of the API but have not yet had a chance to look into what it would take to replace the current way of doing things with a new way.  If you have examples that you can point me to I would really appreciate this.

     

    Thanks for any help that you can provide,

     

    James

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 1, 2013 12:50 PM   in reply to TexasAggieCodeMonkey

    Hey CodeMonkey & Ross,

     

    Did you either of you ever find a solution? I'm stuck too, it seems I can get remote printing on all these PDFs to work but it just prints a blank page since I've been using Javascript in the browser, not Adobe's (they are Engineering drawings that I do not have permission to edit so I can't just insert code into them but I need to make work instructions). I've been scouring the internet for hours now, it seems that this thread is the only relevant/useful one at this point. No one else was trying to achieve this for similar reasons to mine.

     

    Thanks guys,

     

    Lox

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points