效果
预期效果
async outPutPdfFn (id, title) {
const _t = this;
const A4_WIDTH = 592.28;
const A4_HEIGHT = 841.89;
let target = document.getElementById('pdf');
let pageHeight = target.scrollWidth / A4_WIDTH * A4_HEIGHT;
let lableListID = document.getElementsByClassName('item');
for (let i = 0; i < lableListID.length; i++) {
const currentItem = lableListID[i];
let elToTop = document.getElementById('title').offsetTop + currentItem.offsetTop
if (elToTop + currentItem.offsetHeight > pageHeight && elToTop < pageHeight) {
let divParent = currentItem.parentNode;
let newNode = document.createElement('div');
newNode.className = 'emptyDiv';
newNode.style.height = 8 + 'px';
newNode.style.width = '100%';
divParent.insertBefore(newNode, currentItem);
}
}
await _t.$nextTick();
_t.getPdf({
id,
title,
backgroundColor: '#fff'
}).then(base64 => {
uni.postMessage({
data: {
pb: base64,
name: title
}
})
_t.navigateBack();
})
},