Browse Source

[web_demo] 支持上传pdf

yanxin 1 year ago
parent
commit
34e1579f6d

+ 3 - 3
src/MenuView.vue

@@ -16,7 +16,7 @@
         </el-menu-item>
         <el-menu-item index="2" @click="routerJump('/magicColor')">
           <el-col :span="3">🔥</el-col>
-          <span>Magic Color</span>
+          <span>图像锐化并增强</span>
         </el-menu-item>
         <el-menu-item index="3" @click="routerJump('/ocr')">
           <el-col :span="3">🔥</el-col>
@@ -24,11 +24,11 @@
         </el-menu-item>
         <el-menu-item index="4" @click="routerJump('/tableRec')">
           <el-col :span="3">🔥</el-col>
-          <span>Table Recognize</span>
+          <span>通用表格识别</span>
         </el-menu-item>
         <el-menu-item index="5" @click="routerJump('/LayoutAnalysis')">
           <el-col :span="3">🔥</el-col>
-          <span>Layout analysis</span>
+          <span>版面分析</span>
         </el-menu-item>
         <el-menu-item index="6">
           <span></span>

File diff suppressed because it is too large
+ 0 - 554
src/dist/assets/index-5b454dba.js


File diff suppressed because it is too large
+ 576 - 0
src/dist/assets/index-ad165c7d.js


File diff suppressed because it is too large
+ 1 - 1
src/dist/assets/index-0239e196.css


+ 2 - 2
src/dist/index.html

@@ -4,8 +4,8 @@
     <meta charset="UTF-8" />
     <meta name="viewport" content="width=device-width, initial-scale=1.0" />
     <title>DocumentAI Web Demo</title>
-    <script type="module" crossorigin src="./assets/index-5b454dba.js"></script>
-    <link rel="stylesheet" href="./assets/index-0239e196.css">
+    <script type="module" crossorigin src="./assets/index-ad165c7d.js"></script>
+    <link rel="stylesheet" href="./assets/index-d619e929.css">
   </head>
   <body>
     <div id="app"></div>

+ 7 - 65
src/pages/main/views/Detection/LayoutAnalysis.vue

@@ -37,11 +37,6 @@
         <!-- 用于展示图片 -->
         <img id="show-img" class="show-area" />
       </el-row>
-      <div class="pdf-preview" v-show="false">
-        <div class="pdf-wrap">
-          <vue-pdf-embed :source="state.source" :scale="3.0" class="vue-pdf-embed" :page="state.pageNum" />
-        </div>
-      </div>
       <canvas id="canvas"></canvas>
     </el-col>
     <el-col :span="12" class="place">
@@ -245,13 +240,13 @@ const uploadImg = () => {
     reader.onload = () => {
       const post_ = file.name.substring(file.name.lastIndexOf("."), file.name.length).toLowerCase();
       fa_canvas ? fa_canvas.clear() : 0;
-      // if (post_ == ".pdf") {
-      //   state.pageNum = 1;
-      //   state.source = URL.createObjectURL(file);
-      //   is_pdf.value = true
-      //   loadingTask = createLoadingTask(state.source);
-      //   getPdfImage(state.pageNum);
-      // } else 
+      if (post_ == ".pdf") {
+        state.pageNum = 1;
+        state.source = URL.createObjectURL(file);
+        is_pdf.value = true
+        loadingTask = createLoadingTask(state.source);
+        getPdfImage(state.pageNum);
+      } else 
       if (post_ == ".jpg" || post_ == ".png" || post_ == ".bmp" || post_ == ".jpeg") {
         showImg.src = URL.createObjectURL(file);
         showImg.onload = () => {
@@ -560,59 +555,6 @@ async function tableHandleClick(index: any, item: any, rects: any) {
   align-items: center;
 }
 
-.pdf-preview {
-  position: relative;
-  height: 100vh;
-  padding: 20px 0;
-  box-sizing: border-box;
-  background: rgb(66, 66, 66);
-}
-
-.vue-pdf-embed {
-  text-align: center;
-  width: 515px;
-  border: 1px solid #e5e5e5;
-  margin: 0 auto;
-  box-sizing: border-box;
-}
-
-.pdf-preview {
-  position: relative;
-  height: 100vh;
-  padding: 20px 0;
-  box-sizing: border-box;
-  background-color: e9e9e9;
-}
-
-.pdf-wrap {
-  overflow-y: auto;
-}
-
-.vue-pdf-embed {
-  text-align: center;
-  width: 515px;
-  border: 1px solid #e5e5e5;
-  margin: 0 auto;
-  box-sizing: border-box;
-}
-
-.page-tool {
-  position: absolute;
-  /* bottom: 35px; */
-  /* padding-left: 15px; */
-  /* padding-right: 15px; */
-  display: flex;
-  align-items: center;
-  background: rgb(66, 66, 66);
-  color: white;
-  border-radius: 19px;
-  z-index: 100;
-  cursor: pointer;
-  margin-left: 50%;
-  top: 100%;
-  transform: translateX(-50%);
-}
-
 .page-tool-item {
   padding: 8px 15px;
   padding-left: 10px;

+ 32 - 75
src/pages/main/views/ImageProcess/magicColor.vue

@@ -16,21 +16,26 @@
           <el-button type="primary" @click="predict" :loading="loading">Predict</el-button>
         </el-container>
       </div>
-      <el-row v-show="!is_pdf">
-        <img id="show-img" class="show-area" />
-      </el-row>
-      <div class="pdf-preview" v-show="is_pdf">
-        <div class="pdf-wrap">
-          <vue-pdf-embed :source="state.source" :scale="3.0" class="vue-pdf-embed" :page="state.pageNum" />
-        </div>
-        <div class="page-tool">
-          <div class="page-tool-item" @click="prePage">上一页</div>
-          <div class="page-tool-item" @click="nextPage">下一页</div>
+      <div v-show="is_pdf">
+        <el-row>
+          <el-button-group>
+            <el-button type="primary" :icon="ArrowLeft" @click="prePage">上一页</el-button>
+            <el-button type="primary" @click="nextPage">
+              下一页<el-icon class="el-icon--right">
+                <ArrowRight />
+              </el-icon>
+            </el-button>
+          </el-button-group>
           <div class="page-tool-item">{{ state.pageNum }}/{{ state.numPages }}</div>
-          <el-input type="number" v-model="pdf_page"></el-input>
-          <el-button type="primary" @click="SetPdfPage" plain>页面跳转</el-button>
-        </div>
+          <el-container>
+            <el-input type="number" v-model="pdf_page"></el-input>
+            <el-button type="primary" @click="SetPdfPage" plain>页面跳转</el-button>
+          </el-container>
+        </el-row>
       </div>
+      <el-row>
+        <img id="show-img" class="show-area" />
+      </el-row>
       <canvas id="canvas" style="display: none;"></canvas>
     </el-col>
     <el-col :span="12" class="place">
@@ -64,8 +69,10 @@
 import { IMMagicColor, SubmitBug } from '../../../../api/api'
 import { reactive, ref } from 'vue'
 import { onMounted } from "vue";
-
-import VuePdfEmbed from "vue-pdf-embed";
+import {
+  ArrowLeft,
+  ArrowRight,
+} from '@element-plus/icons-vue'
 import { createLoadingTask } from "vue3-pdfjs/esm"; // 获得总页数
 
 import { storeToRefs } from 'pinia'
@@ -118,6 +125,8 @@ function getPdfImage(index: number) {
       });
       canvas.value.toBlob(function (blob) {
         pdf_img.value = dataURLtoBlob(canvas.value.toDataURL('images/png', 1.0))
+        const showImg = document.getElementById("show-img") as HTMLImageElement;
+        showImg.src = canvas.value.toDataURL('images/png', 1.0);
       });
     })
   });
@@ -197,14 +206,14 @@ const uploadImg = () => {
     const file = inputElement.files![0];
     reader.onload = () => {
       const post_ = file.name.substring(file.name.lastIndexOf("."), file.name.length).toLowerCase();
-      // if (post_ == ".pdf") {
-      //   state.pageNum = 1;
-      //   // state.scale = 4;
-      //   state.source = URL.createObjectURL(file);
-      //   is_pdf.value = true
-      //   loadingTask = createLoadingTask(state.source);
-      //   getPdfImage(state.pageNum);
-      // } else 
+      if (post_ == ".pdf") {
+        state.pageNum = 1;
+        // state.scale = 4;
+        state.source = URL.createObjectURL(file);
+        is_pdf.value = true
+        loadingTask = createLoadingTask(state.source);
+        getPdfImage(state.pageNum);
+      } else 
       if (post_ == ".jpg" || post_ == ".png" || post_ == ".bmp" || post_ == ".jpeg") {
         showImg.src = URL.createObjectURL(file);
         is_pdf.value = false
@@ -294,58 +303,6 @@ const submitBug = async () => {
   align-items: center;
 }
 
-.pdf-preview {
-  position: relative;
-  height: 100vh;
-  padding: 20px 0;
-  box-sizing: border-box;
-  background: rgb(66, 66, 66);
-}
-
-.vue-pdf-embed {
-  text-align: center;
-  width: 515px;
-  border: 1px solid #e5e5e5;
-  margin: 0 auto;
-  box-sizing: border-box;
-}
-
-.pdf-preview {
-  position: relative;
-  height: 100vh;
-  padding: 20px 0;
-  box-sizing: border-box;
-  background-color: e9e9e9;
-}
-
-.pdf-wrap {
-  overflow-y: auto;
-}
-
-.vue-pdf-embed {
-  text-align: center;
-  width: 515px;
-  border: 1px solid #e5e5e5;
-  margin: 0 auto;
-  box-sizing: border-box;
-}
-
-.page-tool {
-  position: absolute;
-  /* bottom: 35px; */
-  /* padding-left: 15px; */
-  /* padding-right: 15px; */
-  display: flex;
-  align-items: center;
-  background: rgb(66, 66, 66);
-  color: white;
-  border-radius: 19px;
-  z-index: 100;
-  cursor: pointer;
-  margin-left: 50%;
-  transform: translateX(-50%);
-}
-
 .page-tool-item {
   padding: 8px 15px;
   padding-left: 10px;

+ 28 - 81
src/pages/main/views/Recognize/ocr.vue

@@ -20,25 +20,22 @@
           </el-container>
         </div>
       </el-row>
-      <div class="pdf-preview" v-show="is_pdf">
-        <div class="pdf-wrap">
-          <vue-pdf-embed :source="state.source" :scale="3.0" class="vue-pdf-embed" :page="state.pageNum" />
-        </div>
-        <div class="page-tool">
-          <div class="page-tool-item" @click="prePage">上一页</div>
-          <div class="page-tool-item" @click="nextPage">下一页</div>
+      <div v-show="is_pdf">
+        <el-row>
+          <el-button-group>
+            <el-button type="primary" :icon="ArrowLeft" @click="prePage">上一页</el-button>
+            <el-button type="primary" @click="nextPage">
+              下一页<el-icon class="el-icon--right">
+                <ArrowRight />
+              </el-icon>
+            </el-button>
+          </el-button-group>
           <div class="page-tool-item">{{ state.pageNum }}/{{ state.numPages }}</div>
-        </div>
-        <div style="margin-top: 100px;">
-          <el-row class="page-tool">
-            <div class="common-layout">
-              <el-container>
-                <el-input type="number" v-model="pdf_page"></el-input>
-                <el-button type="primary" @click="SetPdfPage" plain>页面跳转</el-button>
-              </el-container>
-            </div>
-          </el-row>
-        </div>
+          <el-container>
+            <el-input type="number" v-model="pdf_page"></el-input>
+            <el-button type="primary" @click="SetPdfPage" plain>页面跳转</el-button>
+          </el-container>
+        </el-row>
       </div>
     </el-col>
     <el-col :span="8" class="place">
@@ -89,12 +86,14 @@ import { storeToRefs } from 'pinia'
 import OcrLangList from '../../../../components/OcrLangList.vue'
 import { useOcrLangStore } from '../../../../store/OcrLang';
 import { fabric } from 'fabric';
-import { reactive, ref, toRefs, computed } from 'vue'
+import { reactive, ref } from 'vue'
 import { onMounted } from "vue";
 import useClipboard from 'vue-clipboard3'
-import VuePdfEmbed from "vue-pdf-embed";
 import { createLoadingTask } from "vue3-pdfjs/esm"; // 获得总页数
-
+import {
+  ArrowLeft,
+  ArrowRight,
+} from '@element-plus/icons-vue'
 import { useServerIpStore } from '../../../../store/ServerIp';
 import { useServerPortStore } from '../../../../store/ServerPort';
 
@@ -257,14 +256,14 @@ const uploadImg = () => {
     reader.onload = () => {
       const post_ = file.name.substring(file.name.lastIndexOf("."), file.name.length).toLowerCase();
       fa_canvas ? fa_canvas.clear() : 0;
-      // if (post_ == ".pdf") {
-      //   state.pageNum = 1;
-      //   // state.scale = 4;
-      //   state.source = URL.createObjectURL(file);
-      //   is_pdf.value = true
-      //   loadingTask = createLoadingTask(state.source);
-      //   getPdfImage(state.pageNum);
-      // } else 
+      if (post_ == ".pdf") {
+        state.pageNum = 1;
+        // state.scale = 4;
+        state.source = URL.createObjectURL(file);
+        is_pdf.value = true
+        loadingTask = createLoadingTask(state.source);
+        getPdfImage(state.pageNum);
+      } else 
       if (post_ == ".jpg" || post_ == ".png" || post_ == ".bmp" || post_ == ".jpeg") {
         showImg.src = URL.createObjectURL(file);
         showImg.onload = () => {
@@ -494,58 +493,6 @@ function copy(index: any) {
   border-right: solid 1px #ccc;
 }
 
-.pdf-preview {
-  position: relative;
-  height: 100vh;
-  padding: 20px 0;
-  box-sizing: border-box;
-  background: rgb(66, 66, 66);
-}
-
-.vue-pdf-embed {
-  text-align: center;
-  width: 515px;
-  border: 1px solid #e5e5e5;
-  margin: 0 auto;
-  box-sizing: border-box;
-}
-
-.pdf-preview {
-  position: relative;
-  height: 100vh;
-  padding: 20px 0;
-  box-sizing: border-box;
-  background-color: e9e9e9;
-}
-
-.pdf-wrap {
-  overflow-y: auto;
-}
-
-.vue-pdf-embed {
-  text-align: center;
-  width: 515px;
-  border: 1px solid #e5e5e5;
-  margin: 0 auto;
-  box-sizing: border-box;
-}
-
-.page-tool {
-  position: absolute;
-  /* bottom: 35px; */
-  /* padding-left: 15px; */
-  /* padding-right: 15px; */
-  display: flex;
-  align-items: center;
-  background: rgb(66, 66, 66);
-  color: white;
-  border-radius: 19px;
-  z-index: 100;
-  cursor: pointer;
-  margin-left: 50%;
-  transform: translateX(-50%);
-}
-
 .page-tool-item {
   padding: 8px 15px;
   padding-left: 10px;

+ 33 - 81
src/pages/main/views/Recognize/tableRec.vue

@@ -18,24 +18,27 @@
           <el-button type="primary" @click="predict" :loading="loading">Predict</el-button>
         </el-container>
       </div>
-      <el-row v-show="!is_pdf">
+      <div v-show="is_pdf">
+        <el-row>
+          <el-button-group>
+            <el-button type="primary" :icon="ArrowLeft" @click="prePage">上一页</el-button>
+            <el-button type="primary" @click="nextPage">
+              下一页<el-icon class="el-icon--right">
+                <ArrowRight />
+              </el-icon>
+            </el-button>
+          </el-button-group>
+          <div class="page-tool-item">{{ state.pageNum }}/{{ state.numPages }}</div>
+          <el-container>
+            <el-input type="number" v-model="pdf_page"></el-input>
+            <el-button type="primary" @click="SetPdfPage" plain>页面跳转</el-button>
+          </el-container>
+        </el-row>
+      </div>
+      <el-row>
         <!-- 用于展示图片 -->
         <img id="show-img" class="show-area" />
-        <!-- 用于存放真实图片进行文字识别 -->
-        <img id="raw-img" style="display: none" />
       </el-row>
-      <div class="pdf-preview" v-show="is_pdf">
-        <div class="pdf-wrap">
-          <vue-pdf-embed :source="state.source" :scale="3.0" class="vue-pdf-embed" :page="state.pageNum" />
-        </div>
-        <div class="page-tool">
-          <div class="page-tool-item" @click="prePage">上一页</div>
-          <div class="page-tool-item" @click="nextPage">下一页</div>
-          <div class="page-tool-item">{{ state.pageNum }}/{{ state.numPages }}</div>
-          <el-input type="number" v-model="pdf_page"></el-input>
-          <el-button type="primary" @click="SetPdfPage" plain>页面跳转</el-button>
-        </div>
-      </div>
       <canvas id="canvas" style="display: none;"></canvas>
     </el-col>
     <el-col :span="16" class="place">
@@ -71,17 +74,18 @@
 </template>
 
 <script lang='ts' setup>
-import { reactive, ref, toRefs, computed } from 'vue'
+import { reactive, ref } from 'vue'
 import { onMounted } from "vue";
 import { TableRec, SubmitBug } from '../../../../api/api'
-import VuePdfEmbed from "vue-pdf-embed";
 import { createLoadingTask } from "vue3-pdfjs/esm"; // 获得总页数
 import { storeToRefs } from 'pinia'
 import OcrLangList from '../../../../components/OcrLangList.vue'
 import { useOcrLangStore } from '../../../../store/OcrLang';
 import { useBugIdStore } from '../../../../store/BugID';
-import useClipboard from 'vue-clipboard3';
-
+import {
+  ArrowLeft,
+  ArrowRight,
+} from '@element-plus/icons-vue'
 import { useServerIpStore } from '../../../../store/ServerIp';
 import { useServerPortStore } from '../../../../store/ServerPort';
 
@@ -146,14 +150,14 @@ const uploadImg = () => {
     const file = inputElement.files![0];
     reader.onload = () => {
       const post_ = file.name.substring(file.name.lastIndexOf("."), file.name.length).toLowerCase();
-      // if (post_ == ".pdf") {
-      //   state.pageNum = 1;
-      //   // state.scale = 4;
-      //   state.source = URL.createObjectURL(file);
-      //   is_pdf.value = true
-      //   loadingTask = createLoadingTask(state.source);
-      //   getPdfImage(state.pageNum);
-      // } else 
+      if (post_ == ".pdf") {
+        state.pageNum = 1;
+        // state.scale = 4;
+        state.source = URL.createObjectURL(file);
+        is_pdf.value = true
+        loadingTask = createLoadingTask(state.source);
+        getPdfImage(state.pageNum);
+      } else 
       if (post_ == ".jpg" || post_ == ".png" || post_ == ".bmp" || post_ == ".jpeg") {
         showImg.src = URL.createObjectURL(file);
         rawImg.src = URL.createObjectURL(file);
@@ -326,8 +330,8 @@ function getPdfImage(index: number) {
       });
       canvas.value.toBlob(function (blob) {
         pdf_img.value = dataURLtoBlob(canvas.value.toDataURL('images/png', 1.0))
-        // console.log(pdf_img.value);
-        console.log(canvas.value.toDataURL(), state.pageNum)
+        const showImg = document.getElementById("show-img") as HTMLImageElement;
+        showImg.src = canvas.value.toDataURL('images/png', 1.0);
       });
     })
   });
@@ -365,58 +369,6 @@ function nextPage() {
   border-right: solid 1px #ccc;
 }
 
-.pdf-preview {
-  position: relative;
-  height: 100vh;
-  padding: 20px 0;
-  box-sizing: border-box;
-  background: rgb(66, 66, 66);
-}
-
-.vue-pdf-embed {
-  text-align: center;
-  width: auto;
-  border: 1px solid #e5e5e5;
-  margin: 0 auto;
-  box-sizing: border-box;
-}
-
-.pdf-preview {
-  position: relative;
-  height: 100vh;
-  padding: 20px 0;
-  box-sizing: border-box;
-  background-color: e9e9e9;
-}
-
-.pdf-wrap {
-  overflow-y: auto;
-}
-
-.vue-pdf-embed {
-  text-align: center;
-  width: 515px;
-  border: 1px solid #e5e5e5;
-  margin: 0 auto;
-  box-sizing: border-box;
-}
-
-.page-tool {
-  position: absolute;
-  /* bottom: 35px; */
-  /* padding-left: 15px; */
-  /* padding-right: 15px; */
-  display: flex;
-  align-items: center;
-  background: rgb(66, 66, 66);
-  color: white;
-  border-radius: 19px;
-  z-index: 100;
-  cursor: pointer;
-  margin-left: 50%;
-  transform: translateX(-50%);
-}
-
 .page-tool-item {
   padding: 8px 15px;
   padding-left: 10px;