export function printFile(html) {
|
if (!html) return;
|
let userAgent = navigator.userAgent;
|
html = "<style media='print'>.ant-image-mask{display: none;}@page {margin: 0mm; size: landscape;font-size: 10px;} body {padding: 10mm;} table, tbody, thead {width: 100% !important;} td, th {text-align: center;} colgroup {position: absolute; width: 100% !important;}</style><body>" + html + "</body>";
|
if (
|
(userAgent.indexOf("compatible") > -1 &&
|
userAgent.indexOf("MSIE") > -1) ||
|
userAgent.indexOf("Edge") > -1 ||
|
(userAgent.indexOf("Trident") > -1 && userAgent.indexOf("rv:11.0") > -1)
|
) {
|
// IE浏览器
|
let page = window.open("", "_blank"); // 打开一个新窗口,用于打印
|
page.document.write(html); // 写入打印页面的内容
|
page.document.execCommand("print");
|
page.close(); // 关闭打印窗口
|
} else {
|
let doc = document.getElementById('printf');
|
if (doc) {
|
document.getElementById("printElement").removeChild(doc)
|
}
|
let iframe = document.createElement("iframe");
|
iframe.id = "printf";
|
iframe.style.width = "0";
|
iframe.style.height = "0";
|
document.getElementById("printElement").appendChild(iframe);
|
iframe.contentWindow.document.write(html);
|
iframe.contentWindow.focus();
|
iframe.contentWindow.print();
|
}
|
}
|