记录一下开发过程中,趟过的坑。在odoo中,有时候,需要将自定义的网页打印出来(不同于odoo的qweb报表打印),可以如下做;
var head = '' //head标签里面引入的内容
var body = '' //需要打印的网页内容
var iframe = `
<!DOCTYPE html>
<html>
<head>` + head + `
</head>
<body>` + $html.html() +`
</body>
</html>`;
var content_blob = new Blob([iframe], {type: 'text/html'});
$('<iframe style="display:none">').attr({id: 'frame-pdf', name: 'frame-pdf', src: URL.createObjectURL(content_blob )})
.appendTo(document.body)
.on("load", function (responseText, textStatus, jqXHR) {
window.frames['frame-pdf'].focus();
window.frames['frame-pdf'].print();
});