简体   繁体   English

图像未出现在打印预览镶边

[英]Image is not appearing in the print preview chrome

While we want print the HTML page then image is not appearing in print preview, I tried with multiple area but not generate the outoput.虽然我们要打印 HTML 页面,但图像没有出现在打印预览中,但我尝试了多个区域但没有生成输出。 Right Now in print preview it is not showing the correct one.现在在打印预览中它没有显示正确的。 It is very request everyone, Please help for this issue.非常要求大家,请帮助解决这个问题。

Input:输入:

<?xml version="1.0" encoding="UTF-8"?>
<pat id="Main_Window">
    <title>Main Window</title>
    <body>
        <p>The main console screen includes nine panels or areas, which are shown and described below.</p>
        <p><image width="600" href="../MiVBC_Graphics1/MainWindow_CloudlinkChat.bmp" placement="break"/></p>
        <p>Content here</p>
        <p>Content here</p>
        <p>Content here</p>
        <p>Content here</p>
    </body>
</pat>

Java Script code: Java脚本代码:

function printIframe(url, height) {
                var heading_one = window.iframeHeight.heading
                var test = window.iframeHeight.maindivcontent
                console.log(test)
                console.log("fhghfjghdfjghfdg")
                var proxyIframe = document.createElement('iframe');
                var body = document.getElementsByTagName('body')[0];
                body.appendChild(proxyIframe);
                proxyIframe.style.width = '100%';
                proxyIframe.style.height = '100%';
                proxyIframe.style.display = 'none';
                var contentWindow = proxyIframe.contentWindow;
                contentWindow.document.open();
                var is_chrome = Boolean(contentWindow.chrome);
                contentWindow.document.write(test)
                contentWindow.document.write('<iframe onload="print();" frameborder="0" marginheight="0" marginwidth="0"></iframe>');
                contentWindow.document.close(); 
                if (is_chrome) {
                    contentWindow.onload = function() { 
                    };
                }
                else {contentWindow.document.write('<iframe onload="print();" frameborder="0" marginheight="0" marginwidth="0"></iframe>');
    contentWindow.document.close(); }return true;}

Does it still show up for you outside of print mode?在打印模式之外它是否仍然显示给您? Because when I test your code it doesn't.因为当我测试你的代码时它没有。 However, it works when you change the img href to src :但是,当您将img href更改为src时,它会起作用:

<p><image width="600" src="../MiVBC_Graphics1/MainWindow_CloudlinkChat.bmp" placement="break"/></p>

You need to set a timeout to give the browser some time to render the images.您需要设置一个超时来给浏览器一些时间来呈现图像。 Try this:尝试这个:

setTimeout(function() {
    contentWindow.print();
    contentWindow.close();
}, 250);

And you also need to used src instead of href而且您还需要使用 src 而不是 href

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM