Browse Source

add: 添加 flatten 功能

liutian 1 year ago
parent
commit
7ee772ac46

+ 36 - 0
packages/core/src/index.js

@@ -65,6 +65,7 @@ class ComPDFKitViewer {
       uploadUrl: '/web-viewer/annotate/openPdfToAnnotate',
       editUrl: '/web-viewer/annotate/edit',
       saveUrl: '/web-viewer/annotate/save',
+      flattenUrl: '/web-viewer/annotate/saveAndFlatten',
       uploadAnnotationsUrl: '/web-viewer/annotate/importAnnotateToPdf',
       downloadAnnotation: '/web-viewer/annotate/exportAnnotate',
       compareUrl: '/v1/pdf/compareto'
@@ -819,6 +820,41 @@ class ComPDFKitViewer {
     this.percent = percent;
   }
 
+  flattenPdfDownload () {
+    if (this._token && this._pdfId) {
+      const data = {
+        method: 'POST',
+        headers: {
+          "Content-Type": "application/json",
+          'Authorization': this._token
+        },
+        body: JSON.stringify({
+          pdfId: this._pdfId
+        })
+      }
+      return fetch(this.optionUrl.webviewBaseUrl + this.optionUrl.flattenUrl, data)
+        .then((res) => {
+          return res.json()
+        })
+        .then((data) => {
+          if (data.code === "200") {
+            console.log(data)
+            // this.downloadManager.downloadUrl(data.data.newFileUrl, this._docName)
+            saveAs(data.data.newFileUrl, this._docName)
+            return data.data.newFileUrl
+          } else {
+            return false
+          }
+        })
+        .catch((error) => {
+          console.log(error)
+          return false
+        });
+    } else {
+      return false
+    }
+  }
+
   download (download = true) {
     if (this._token && this._pdfId) {
       const data = {

+ 17 - 2
packages/webview/src/components/Dropdown/Dropdown.vue

@@ -16,6 +16,7 @@
     </template>
     <div class="drop-down">
       <div class="drop-item" @click="downloadFile"><DownloadButton />Download</div>
+      <div class="drop-item" @click="handleFlatten"><FlattenButton />Save as Flattened PDF</div>
       <div class="drop-item" @click="handlePrint"><PrintButton />Print</div>
     </div>
   </n-popover>
@@ -31,8 +32,8 @@
   
   const popover = ref(null)
   
-  const { download, webViewerNamedAction } = core
-  
+  const { download, webViewerNamedAction, flattenPdfDownload } = core
+
   const popoverChanged = computed(() => useViewer.getPopoverChanged)
   const showDropdown = computed(() => popover.value && popover.value.getMergedShow())
 
@@ -56,6 +57,20 @@
     }
   }
 
+  const handleFlatten = async () => {
+    useViewer.setDownloading(true)
+    try {
+      console.log(flattenPdfDownload)
+      const res = await flattenPdfDownload()
+      useViewer.setDownloading(false)
+      if (!res) {
+        useViewer.setDownloadError('Downloaded')
+      }
+    } catch (error) {
+      console.log(error)
+    }
+  }
+
   const handlePrint = async() => {
     useViewer.setDownloading(true)
     try {

+ 5 - 0
packages/webview/src/components/FlattenButton/FlattenButton.vue

@@ -0,0 +1,5 @@
+<template>
+  <Button>
+    <Flatten />
+  </Button>
+</template>

File diff suppressed because it is too large
+ 5 - 0
packages/webview/src/components/Icon/Flatten.vue


File diff suppressed because it is too large
+ 1 - 1
packages/webview/src/components/Icon/More.vue


+ 3 - 0
packages/webview/src/core/flattenPdfDownload.js

@@ -0,0 +1,3 @@
+import core from '@/core'
+
+export default () => core.getDocumentViewer().flattenPdfDownload()

+ 3 - 1
packages/webview/src/core/index.js

@@ -36,6 +36,7 @@ import setDefaultSelect from './setDefaultSelect'
 import handleField from './handleField'
 import handleSign from './handleSign'
 import handleStamp from './handleStamp'
+import flattenPdfDownload from './flattenPdfDownload'
 
 
 export default {
@@ -79,5 +80,6 @@ export default {
   setDefaultSelect,
   handleField,
   handleSign,
-  handleStamp
+  handleStamp,
+  flattenPdfDownload
 }