<view class="popupBoxTheReport" ref="pdfContent" id="pdfContent">
<view style="width:100%;height:800px">
导出测试
</view>
</view>
<view class="toPage" v-show="!statueValue" @click="exportReport(reportObj)">
导出报告
</view>
在script上引入,
import html2canvas from 'html2canvas';
import jsPDF from 'jspdf';
导出方法
async exportReport() {
const pdf = new jsPDF();
// 假设你的内容元素有一个特定的ID
const content = document.getElementById('pdfContent');
console.log("content", content.style.maxHeight);
html2canvas(content, {
useCORS: true
}).then(canvas => {
// 将canvas转换为图片
const imgData = canvas.toDataURL('image/png');
// 添加图片到PDF
const imgProps = pdf.getImageProperties(imgData);
const pdfWidth = pdf.internal.pageSize.getWidth();
const pdfHeight = (imgProps.height * pdfWidth) / imgProps.width;
pdf.addImage(imgData, 'PNG', 0, 0, pdfWidth, pdfHeight);
// 保存PDF
pdf.save('downloaded.pdf');
});
},