From fe53187de649ff276bae8ecf160dc89c4b60e35b Mon Sep 17 00:00:00 2001
From: spring <2396852758@qq.com>
Date: 星期二, 04 三月 2025 13:54:59 +0800
Subject: [PATCH] Merge branch 'master' of http://114.132.189.42:9002/r/center-lims-before-ruoyi
---
src/utils/downHtmlToPDF.js | 22 ++++++++++++++++++++++
1 files changed, 22 insertions(+), 0 deletions(-)
diff --git a/src/utils/downHtmlToPDF.js b/src/utils/downHtmlToPDF.js
new file mode 100644
index 0000000..3e83e09
--- /dev/null
+++ b/src/utils/downHtmlToPDF.js
@@ -0,0 +1,22 @@
+import html2canvas from "html2canvas";
+import jsPDF from "jspdf";
+
+export async function exportHtmlToPDF(element, name = "exported") {
+ try {
+ // 灏� HTML 鍏冪礌杞崲涓� canvas
+ console.log("姝e湪灏� HTML 杞崲涓� canvas...", element);
+ const canvas = await html2canvas(element, { useCORS: true });
+ const imgData = canvas.toDataURL("image/png");
+
+ // 鍒涘缓 PDF
+ const pdf = new jsPDF("p", "mm", "a4");
+ const pdfWidth = pdf.internal.pageSize.getWidth();
+ const pdfHeight = (canvas.height * pdfWidth) / canvas.width;
+
+ pdf.addImage(imgData, "PNG", 10, 10, pdfWidth - 20, pdfHeight - 20);
+ pdf.save(name + ".pdf");
+ console.log("PDF 瀵煎嚭鎴愬姛锛�");
+ } catch (error) {
+ console.error("瀵煎嚭 PDF 澶辫触锛�", error);
+ }
+}
--
Gitblit v1.9.3