|
@@ -43,12 +43,14 @@ const htmltopdf = {
|
|
|
// 根据 A4 的宽高计算 DOM 页面一页应该对应的高度
|
|
|
let pageheight = printdom.offsetWidth / 592.28 * 880;
|
|
|
// 将所有不允许被截断的元素进行处理
|
|
|
- let wholeNodes = document.querySelectorAll('p,table');
|
|
|
+ // let wholeNodes = document.querySelectorAll('p,table,.page-break');
|
|
|
+ let wholeNodes = document.querySelectorAll('p,table,.page-break');
|
|
|
for (let i = 0; i < wholeNodes.length; i++) {
|
|
|
// 1. 判断当前的不可分页元素是否在两页显示
|
|
|
const topPagenum = Math.ceil((wholeNodes[i].offsetTop) / pageheight);
|
|
|
const bottomPagenum = Math.ceil((wholeNodes[i].offsetTop + wholeNodes[i].offsetHeight) / pageheight);
|
|
|
if (topPagenum!== bottomPagenum) {
|
|
|
+ debugger
|
|
|
// 说明该 DOM 会被截断
|
|
|
// 2. 插入空白块使被截断元素下移
|
|
|
let divParent = wholeNodes[i].parentNode;
|
|
@@ -57,7 +59,7 @@ const htmltopdf = {
|
|
|
newBlock.style.background = '#fff';
|
|
|
// 3. 计算插入空白块的高度,可以适当流出空间使得内容不太靠边,根据自己需求而定
|
|
|
let _h = topPagenum * pageheight - wholeNodes[i].offsetTop;
|
|
|
- newBlock.style.height = _h + 20 + 'px';
|
|
|
+ newBlock.style.height = _h + 24 + 'px';
|
|
|
divParent.insertBefore(newBlock, wholeNodes[i]);
|
|
|
}
|
|
|
}
|