5

I was wondering if it is possible to print the data of an object tag in html? For example I have an object like this:

<object id="myObject" data="myPDF.pdf"></object>

I have a PDF embedded in the object tag. I need to be able to print the PDF using a JavaScript function in Firefox. Placing the PDF in an iframe and printing does not work as Firefox will not let you access the frame's contents. Neither does using:

myObject.contentWindow.print();

or

document.getElementById("myObject").print(); 

Does anyone have any other suggestions? I am trying to figure out a way of printing just the data of the object (i.e. the PDF file) but have not found a solution so far. Using an iframe works for chrome and using an embed tag works for Internet Explorer, but I cannot find anything that will work in Firefox. Any help is much appreciated, thanks.

Celt
  • 2,469
  • 2
  • 26
  • 43
  • 1
    possible duplicate of [Print PDF directly from JavaScript](http://stackoverflow.com/questions/16239513/print-pdf-directly-from-javascript) – Pete Aug 26 '14 at 12:50
  • No I stated in my question that the method in that question did not work for me. When I try using: document.getElementById("myObject").print(); the console says the method does not exist. – Celt Aug 26 '14 at 12:52
  • @Celt The second statement is complete wrong, because `document.getElementById("myObject")` returns a dom object (a representation of memory). – Reporter Aug 26 '14 at 12:55
  • Hmm I didn't realise that, is there a way of accessing the object and then calling the a print() function? – Celt Aug 26 '14 at 12:57
  • Try this: http://stackoverflow.com/a/6168091/501196 – yms Aug 26 '14 at 13:04
  • Thanks but that does not work in FF either, the console says the print() method does not exist.. – Celt Aug 26 '14 at 13:09
  • @Celt I think it isn't possible, because the pdf file will be opend by the pdf plugin. For the browser itself are the data unknown and not convertable. – Reporter Aug 26 '14 at 14:13
  • I was having that problem in IE but when I set the type to application/pdf the printing worked fine, nothing I have tried will work for FF though. – Celt Aug 26 '14 at 14:15
  • 2
    This seems to be a bug in firefox, not sure if it has been fixed: https://bugzilla.mozilla.org/show_bug.cgi?id=911444 – yms Aug 26 '14 at 19:22

1 Answers1

1

Unfortunately as @yms said in the comments this is a bug in Firefox and there is no workaround for it yet. You can read the bug report here. There does not seem to be any progress on a fix but I will update this answer as soon as I hear of one.

Celt
  • 2,469
  • 2
  • 26
  • 43
  • No still has not been resolved as far as I know. I have just given up on it and am waiting for the bug fix from Mozilla. – Celt Mar 18 '15 at 11:06