From f79a7fc117f8abb821c618e228ca794d46b1766d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A1=97=E8=A7=92=E5=B0=8F=E6=9E=97?= <1013335014@qq.com> Date: Mon, 11 Dec 2023 09:57:32 +0800 Subject: [PATCH] =?UTF-8?q?Feat=EF=BC=9A=E5=87=8F=E5=B0=8F=E5=AF=BC?= =?UTF-8?q?=E5=87=BA=E7=9A=84pdf=E4=BD=93=E7=A7=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simple-mind-map/src/plugins/ExportPDF.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/simple-mind-map/src/plugins/ExportPDF.js b/simple-mind-map/src/plugins/ExportPDF.js index 82a93b38..801193f6 100644 --- a/simple-mind-map/src/plugins/ExportPDF.js +++ b/simple-mind-map/src/plugins/ExportPDF.js @@ -20,7 +20,11 @@ class ExportPDF { // 单页导出 onePageExport(name, img) { return new Promise((resolve, reject) => { - let pdf = new JsPDF('', 'pt', 'a4') + let pdf = new JsPDF({ + unit: 'pt', + format: 'a4', + compress: true + }) let a4Ratio = a4Size.width / a4Size.height let image = new Image() image.onload = () => { @@ -75,7 +79,11 @@ class ExportPDF { // a4纸的尺寸[595.28,841.89],图片在pdf中图片的宽高 let imgWidth = a4Size.width let imgHeight = (a4Size.width / imageWidth) * imageHeight - let pdf = new JsPDF('', 'pt', 'a4') + let pdf = new JsPDF({ + unit: 'pt', + format: 'a4', + compress: true + }) // 有两个高度需要区分,一个是图片的实际高度,和生成pdf的页面高度(841.89) // 当内容未超过pdf一页显示的范围,无需分页 if (leftHeight < pageHeight) { @@ -102,7 +110,7 @@ class ExportPDF { pdf.save(name) resolve() } - image.onerror = (e) => { + image.onerror = e => { reject(e) } image.src = img