Js设置打印缩放
近期需要优化一个打印项目,因为是固定长度,所以需要缩放打印,记录一下
//获取打印的页面内容
let subOutputRankPrint = document.getElementById('print-div');
let newContent = subOutputRankPrint.innerHTML;
let oldContent = document.body.innerHTML;
document.body.innerHTML = newContent;
//页面打印缩放比例设置
document.getElementsByTagName('body')[0].style.zoom=0.92;
//检测是否是IE 如果是ie进行页眉页脚
if(!!window.ActiveXObject || "ActiveXObject" in window){
var hkey_root, hkey_path, hkey_key;
hkey_path = "HKEY_CURRENT_USER\\Software\\Microsoft\\Internet"+
"Explorer\\PageSetup\\";
try {
var RegWsh = new ActiveXObject("WScript.Shell");
RegWsh.RegWrite(hkey_path + "header", "");
RegWsh.RegWrite(hkey_path + "footer", "");
} catch (e) {}
}
window.print();
window.location.reload();
//将原有页面还原到页面
document.body.innerHTML = oldContent;