diff --git a/frontend/package.json b/frontend/package.json
index d33d755db0..d06d31858f 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -28,6 +28,7 @@
"html2canvasde": "^v1.1.4-de",
"js-cookie": "2.2.0",
"jsencrypt": "^3.0.0-rc.1",
+ "jspdf": "^2.3.1",
"lodash": "4.17.21",
"normalize.css": "7.0.0",
"nprogress": "0.2.0",
diff --git a/frontend/src/lang/en.js b/frontend/src/lang/en.js
index 8532718ef6..011ffcfa21 100644
--- a/frontend/src/lang/en.js
+++ b/frontend/src/lang/en.js
@@ -1129,6 +1129,7 @@ export default {
store: 'Store',
save_to_panel: 'Save to template',
export_to_panel: 'Export to template',
+ export_to_pdf: 'Export to PDF',
preview: 'Preview',
fullscreen_preview: 'Fullscreen Preview',
new_tab_preview: 'New Tab Preview',
diff --git a/frontend/src/lang/tw.js b/frontend/src/lang/tw.js
index 16e2f4543b..f251e2d5a6 100644
--- a/frontend/src/lang/tw.js
+++ b/frontend/src/lang/tw.js
@@ -1128,6 +1128,7 @@ export default {
store: '收藏',
save_to_panel: '保存為模板',
export_to_panel: '導出為模板',
+ export_to_pdf: '導出為PDF',
preview: '預覽',
fullscreen_preview: '全屏預覽',
new_tab_preview: '新Tab頁預覽',
diff --git a/frontend/src/lang/zh.js b/frontend/src/lang/zh.js
index e2d201ea11..add3e55efc 100644
--- a/frontend/src/lang/zh.js
+++ b/frontend/src/lang/zh.js
@@ -1130,6 +1130,7 @@ export default {
store: '收藏',
save_to_panel: '保存为模板',
export_to_panel: '导出为模板',
+ export_to_pdf: '导出为PDF',
preview: '预览',
fullscreen_preview: '全屏预览',
new_tab_preview: '新Tab页预览',
diff --git a/frontend/src/views/panel/list/PanelViewShow.vue b/frontend/src/views/panel/list/PanelViewShow.vue
index 0d912b2b10..d45d619e1f 100644
--- a/frontend/src/views/panel/list/PanelViewShow.vue
+++ b/frontend/src/views/panel/list/PanelViewShow.vue
@@ -21,6 +21,11 @@
+
+
+
+
+
@@ -80,6 +85,7 @@ import html2canvas from 'html2canvasde'
import FileSaver from 'file-saver'
import { enshrineList, saveEnshrine, deleteEnshrine } from '@/api/panel/enshrine'
import bus from '@/utils/bus'
+import JsPDF from 'jspdf'
export default {
name: 'PanelViewShow',
components: { Preview, SaveToTemplate },
@@ -172,6 +178,33 @@ export default {
}
})
},
+
+ downloadAsPDF() {
+ html2canvas(this.$refs.imageWrapper).then(canvas => {
+ const contentWidth = canvas.width
+ const contentHeight = canvas.height
+ const pageHeight = contentWidth / 592.28 * 841.89
+ let leftHeight = contentHeight
+ let position = 0
+ const imgWidth = 595.28
+ const imgHeight = 592.28 / contentWidth * contentHeight
+ const pageData = canvas.toDataURL('image/jpeg', 1.0)
+ const PDF = new JsPDF('', 'pt', 'a4')
+ if (leftHeight < pageHeight) {
+ PDF.addImage(pageData, 'JPEG', 0, 0, imgWidth, imgHeight)
+ } else {
+ while (leftHeight > 0) {
+ PDF.addImage(pageData, 'JPEG', 0, position, imgWidth, imgHeight)
+ leftHeight -= pageHeight
+ position -= 841.89
+ if (leftHeight > 0) {
+ PDF.addPage()
+ }
+ }
+ }
+ PDF.save('PDF-test' + '.pdf')
+ })
+ },
refreshTemplateInfo() {
this.templateInfo = {}
html2canvas(this.$refs.imageWrapper).then(canvas => {