问题描述:
项目中使用PDF打印,Google浏览器和ie都有默认的页眉页脚,页面四个角有时间,页码,网址,甚至还有undefined。
解决方案:
1.使用css样式,将页眉页脚去除。
2.ie兼容处理,(js函数)
一.Chrome处理
<style scoped>
@page {
size:auto !important;
height: 100% !important;
margin: 3mm 0 0 10mm !important;
}
</style>
二.ie处理
methods: {
print_page() {
if (!!window.ActiveXObject || 'ActiveXObject' in window) { // 是否ie
this.remove()
}
// window.print()
},
remove() {
var hkey_path
hkey_path = 'HKEY_CURRENT_USER\\Software\\Microsoft\\Internet Explorer\\PageSetup\\'
try {
var RegWsh = new window.ActiveXObject('WScript.Shell')
RegWsh.RegWrite(hkey_path + 'header', '')
RegWsh.RegWrite(hkey_path + 'footer', '')
} catch (e) {
}
},
}
<el-button v-print="#toPrint" type="primary" @click="print_page">打印机打印</el-button>