图像没有出现在打印预览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 Script代码:

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

最新更新