2

We display vf pages rendered as pdfs in a lightning component which generates these documents. We would like to implement a print all button that would print the contents of all the iframes. I have searched around and found solutions for how to print iframes using js but they do not seem to work.

Does anyone have any info or advise of how to approach this? I figured it would be easier to do in JS but maybe it is something that can be done server side?

EDIT: I have referenced this: https://stackoverflow.com/questions/25682414/how-can-i-print-iframe-content

I put together:

In Lightning Component

<iframe id="printf" name="printf" src="{!'/apex/inscor__ReleaseCertificate?Id=' + rl.Id+v.asaurl}" width="100%" height="500px;" frameBorder="0" />

JS Controller

printAll : function(component) {
  window.frames["printf"].focus();
  window.frames["printf"].print();
}

Also tried

printAll : function(component) {
  var frm = document.getElementById('printf').contentWindow;
  frm.focus();// focus on contentWindow is needed on some ie versions
  frm.print();
}

I get this error when trying:

Uncaught DOMException: Blocked a frame with origin "https://efficiency-site- 
8076-dev-ed.lightning.force.com" from accessing a cross-origin frame.
at <anonymous>:1:8
(anonymous) @ VM6417:1

I started just trying to print one iframe but will eventually need to print all of the documents displayed on the screen if possible.

2
  • 1
    "I have searched around and found solutions for how to print iframes using js but they do not seem to work." Are you able to post what you tried so we can see why that wouldn't be working? Aug 2, 2018 at 17:04
  • Updated posting Aug 2, 2018 at 17:08

0

You must log in to answer this question.

Browse other questions tagged .