0

I'm displaying a PDF within an Iframe and I have a dynamic button which says Print. On the click of that button, I want to print only the PDF which is displayed in the iframe and not the complete page. I'm using the below code to print but it is printing the whole page.

try {
iframe = document.getElementById('id of iframe');
iframe.contentWindow.document.execCommand('print', false, null);
}

catch (e) {
window.print();
}

How can I print only the content of the iframe which is the PDF in this case?

Luke Girvin
  • 13,221
  • 9
  • 64
  • 84

1 Answers1

0

If your button is outside of iframe, then the click action would set focus to parent window instead of the iframe that has content to get printed.

refer this post if this is the case: Setting focus to iframe contents

Community
  • 1
  • 1