繁体   English   中英

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

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

虽然我们要打印 HTML 页面,但图像没有出现在打印预览中,但我尝试了多个区域但没有生成输出。 现在在打印预览中它没有显示正确的。 非常要求大家,请帮助解决这个问题。

输入:

<?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脚本代码:

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;}

在打印模式之外它是否仍然显示给您? 因为当我测试你的代码时它没有。 但是,当您将img href更改为src时,它会起作用:

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

您需要设置一个超时来给浏览器一些时间来呈现图像。 尝试这个:

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

而且您还需要使用 src 而不是 href

暂无
暂无

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

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