import jsPDF from 'jspdf';
import html2canvas from 'html2canvas';
html2canvas(document.getElementById("_container")).then(function (canvas) {
const contentWidth = canvas.width;
const contentHeight = canvas.height;
const pageData = canvas.toDataURL('image/jpeg', 1.0);
const pdfX = (contentWidth + 10) / 2 * 0.75;
const pdfY = (contentHeight + 500) / 2 * 0.75 ;// 500为底部留白
const imgX = pdfX;
const imgY = (contentHeight / 2 * 0.75); //内容图片这里不需要留白的距离
const PDF = new jsPDF('', 'pt', [pdfX, pdfY]);
PDF.addImage(pageData, 'jpeg', 0, 0, imgX, imgY);
PDF.save('download.pdf');
});
react html2canvas生成pdf
最新推荐文章于 2024-04-12 16:13:45 发布