vue实现打印后的页面直接打印
/*
* 处理blob接口返回值或弹窗打印pdf
* */
export function getBlobResult(data) {
const binaryData = [];
binaryData.push(data);
let blob = new Blob(binaryData, { type: data.type })
//弹出打印
console.log("data.type", data.type)
if (data.type == "application/pdf") {
let urlPdf = window.URL.createObjectURL(blob);
//打印出来的页面直接调打印控件(以下三行)
let newWindow = window.open(urlPdf, '__blank');
newWindow.document.close(); //关闭document的输出流, 显示选定的数据
newWindow.print(); //打印当前窗口
} else {
//异常返回
const reader = new FileReader();
reader.readAsText(blob, 'utf-8');
reader.onloadend = function () {
let errorMsg = reader.result.substring(9);
Message.error(errorMsg)
}
return;
}
return "";
}