js打印代碼
xxxxxxxxxx
15
1
var iframe = document.getElementById("print-iframe");
2
if (!iframe) {
3
var el = document.getElementById("print_content");
4
iframe = document.createElement('IFRAME');
5
var doc;
6
iframe.setAttribute("id", "print-iframe");
7
document.body.appendChild(iframe);
8
doc = iframe.contentWindow.document;
9
//这里可以自定义样式
10
doc.write('<div style="width: 500px;">' + el.innerHTML + '</div>');
11
doc.close();
12
iframe.contentWindow.focus();
13
}
14
iframe.contentWindow.print();
15
document.body.removeChild(iframe);
已复制
xml代碼
xxxxxxxxxx
6
1
<div style="display: flex;flex-direction: column;align-items: center">
2
<div id="print_content" style="width: 200px;">
3
<img style="width: 100%;" t-attf-src="data:image/png;base64,#{widget.value}"/>
4
</div>
5
<button class="btn btn-primary btn-sm">打印</button>
6
</div>
已复制