0

The issue is related to printing the content in the iframe from the normal HTML file.

I have created an HTML file where I am just including an Iframe and passing the src with the online sample PDF file URL(for testing purpose). But after the HTML file is loaded and I tried to print the page using Ctrl + P, the page is printed without the iframe file.

I don't want to add a button to the HTML which will print the content of the iframe. I want to print the iframe content directly from the parent window.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>My Page</title>
         <style type="text/css">
    body, html {
        margin: 0;
        padding: 0;
        height: 100%;
        overflow: hidden;
    }
    #content {
        position: absolute;
        left: 0;
        right: 0;
        bottom: 0;
        top: 0px;
    }
</style>
</head>
<body>
<div id="content">
    <iframe id="printf" name="printf" src="http://www.africau.edu/images/default/sample.pdf" width="100%" height="98%"  frameborder="0" allowfullscreen></iframe>
</div>
</body>
</html>

Any ideas on how to achieve this?

The result prints the outer page and not the content within the iframe.

Samrat Sarang
  • 131
  • 1
  • 4
  • In the button click handler function do: `document.querySelector('#printf').focus(); window.print();`. – Teemu Apr 10 '19 at 14:19
  • Possible duplicate of [Javascript Print iframe contents only](https://stackoverflow.com/questions/9616426/javascript-print-iframe-contents-only) – Daniel Beck Apr 10 '19 at 14:41
  • @DanielBeck, The above approach will not work every time, it will only work on body load. I want it to work everytime I click print from parent form or by using Ctrl + P. shortcut. – Samrat Sarang Apr 15 '19 at 06:37

0 Answers0