|
@@ -1,24 +1,24 @@
|
|
|
<template>
|
|
|
- <div class="page">
|
|
|
- <div class="common-layout">
|
|
|
- <el-container>
|
|
|
- <el-header class="header">
|
|
|
- <h2>PDF转Word</h2>
|
|
|
- <p>将PDF文档转换为Word。转换出的文件尽可能保持PDF原有格式(目前暂不支持文字大小,颜色与样式,不支持分栏排版)</p>
|
|
|
- </el-header>
|
|
|
- <el-main class="main">
|
|
|
- <FileUpload fileFormats="pdf" :isConvert="true" />
|
|
|
- </el-main>
|
|
|
- <el-footer class="footer">
|
|
|
- <OcrLangList />
|
|
|
- <el-button type="primary" @click="predict" :loading="loading">开始转换</el-button>
|
|
|
- <el-button type="primary" @click="download" :loading="loading">下载结果</el-button>
|
|
|
- <section class="predict-time">耗时:{{ predictTime }} ms</section>
|
|
|
- </el-footer>
|
|
|
- </el-container>
|
|
|
- </div>
|
|
|
+ <div class="page">
|
|
|
+ <div class="common-layout">
|
|
|
+ <el-container>
|
|
|
+ <el-header class="header">
|
|
|
+ <h2>PDF转Word</h2>
|
|
|
+ <p>将PDF文档转换为Word。转换出的文件尽可能保持PDF原有格式(目前暂不支持文字大小,颜色与样式,不支持分栏排版)</p>
|
|
|
+ </el-header>
|
|
|
+ <el-main class="main">
|
|
|
+ <FileUpload fileFormats="pdf" :isConvert="true" />
|
|
|
+ </el-main>
|
|
|
+ <el-footer class="footer">
|
|
|
+ <OcrLangList />
|
|
|
+ <el-button type="primary" @click="predict" :loading="loading">开始转换</el-button>
|
|
|
+ <el-button type="primary" @click="download" :loading="loading">下载结果</el-button>
|
|
|
+ <section class="predict-time">耗时:{{ predictTime }} ms</section>
|
|
|
+ </el-footer>
|
|
|
+ </el-container>
|
|
|
</div>
|
|
|
- </template>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
import { ref } from 'vue'
|
|
@@ -45,51 +45,60 @@ let loading = ref(false)
|
|
|
const output_path = ref("")
|
|
|
|
|
|
const predict = async () => {
|
|
|
- fileName.value = ''
|
|
|
- fileName.value = input_file.value?.name
|
|
|
- if (fileName.value == undefined || fileName.value == '') {
|
|
|
- alert('请上传文件!')
|
|
|
- return;
|
|
|
- }
|
|
|
- if (ocr_lang.value == undefined || ocr_lang.value == "") {
|
|
|
- alert('请先指定语言!')
|
|
|
- return;
|
|
|
- }
|
|
|
+ fileName.value = ''
|
|
|
+ fileName.value = input_file.value?.name
|
|
|
+ if (fileName.value == undefined || fileName.value == '') {
|
|
|
+ alert('请上传文件!')
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (ocr_lang.value == undefined || ocr_lang.value == "") {
|
|
|
+ alert('请先指定语言!')
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- loading.value = !loading.value
|
|
|
- var data = new FormData();
|
|
|
- data.append('pdf', input_file.value);
|
|
|
- data.append('lang', ocr_lang.value);
|
|
|
- data.append('page_range', "None");
|
|
|
+ loading.value = !loading.value
|
|
|
+ var data = new FormData();
|
|
|
+ data.append('pdf', input_file.value);
|
|
|
+ data.append('lang', ocr_lang.value);
|
|
|
+ data.append('page_range', "None");
|
|
|
|
|
|
- PDFToWord(api_pdf_to_word.value, data).then(res => {
|
|
|
- console.log(res)
|
|
|
- predictTime.value = res.data.cost;
|
|
|
- output_path.value = res.data.file_path;
|
|
|
- loading.value = !loading.value;
|
|
|
- }).catch(function (err) {
|
|
|
- loading.value = !loading.value;
|
|
|
- predictTime.value = 0
|
|
|
- });
|
|
|
+ PDFToWord(api_pdf_to_word.value, data).then(res => {
|
|
|
+ loading.value = !loading.value;
|
|
|
+ console.log(res)
|
|
|
+ output_path.value = ''
|
|
|
+ predictTime.value = 0
|
|
|
+ if (res.code == 400) {
|
|
|
+ alert('pdf页面超过100页!避免转换时间过长请输入少于100页的pdf文件!')
|
|
|
+ return
|
|
|
+ } else if (res.code == 401) {
|
|
|
+ alert('输入了非法的pdf页面范围!请输入正确的pdf页面范围!')
|
|
|
+ return
|
|
|
+ }
|
|
|
+ predictTime.value = res.data.cost;
|
|
|
+ output_path.value = res.data.file_path;
|
|
|
+ }).catch(function (err) {
|
|
|
+ loading.value = !loading.value;
|
|
|
+ predictTime.value = 0
|
|
|
+ });
|
|
|
};
|
|
|
|
|
|
const download = async () => {
|
|
|
- if (output_path.value != "") {
|
|
|
- Download(api_download.value, output_path.value).then(res => {
|
|
|
- const url = window.URL.createObjectURL(res)
|
|
|
- const a = document.createElement('a')
|
|
|
- a.href = url
|
|
|
- a.download = fileName.value.split('.')[0] + '.docx'
|
|
|
- document.body.appendChild(a)
|
|
|
- a.click()
|
|
|
- document.body.removeChild(a)
|
|
|
- window.URL.revokeObjectURL(url)
|
|
|
- }).catch(function (err) {
|
|
|
- console.log(err)
|
|
|
- });
|
|
|
- }
|
|
|
- else
|
|
|
- alert('请先上传pdf文件并等待成功转换')
|
|
|
+ if (output_path.value != "") {
|
|
|
+ Download(api_download.value, output_path.value).then(res => {
|
|
|
+ const url = window.URL.createObjectURL(res)
|
|
|
+ const a = document.createElement('a')
|
|
|
+ a.href = url
|
|
|
+ a.download = fileName.value.split('.')[0] + '.docx'
|
|
|
+ document.body.appendChild(a)
|
|
|
+ a.click()
|
|
|
+ document.body.removeChild(a)
|
|
|
+ window.URL.revokeObjectURL(url)
|
|
|
+ }).catch(function (err) {
|
|
|
+ console.log(err)
|
|
|
+ });
|
|
|
+ }
|
|
|
+ else
|
|
|
+ alert('请先上传pdf文件并等待成功转换')
|
|
|
}
|
|
|
</script>
|
|
|
|
|
@@ -98,6 +107,7 @@ const download = async () => {
|
|
|
width: 100%;
|
|
|
height: 100%;
|
|
|
}
|
|
|
+
|
|
|
.common-layout {
|
|
|
width: 100%;
|
|
|
height: 100%;
|
|
@@ -106,20 +116,24 @@ const download = async () => {
|
|
|
justify-content: center;
|
|
|
align-items: center;
|
|
|
}
|
|
|
+
|
|
|
.header {
|
|
|
height: 10%;
|
|
|
}
|
|
|
+
|
|
|
.main {
|
|
|
height: 800px;
|
|
|
width: 100%;
|
|
|
position: relative;
|
|
|
}
|
|
|
+
|
|
|
.footer {
|
|
|
display: flex;
|
|
|
justify-content: center;
|
|
|
align-items: center;
|
|
|
width: 100%;
|
|
|
}
|
|
|
+
|
|
|
.predict-time {
|
|
|
margin-left: 20px;
|
|
|
}
|