Merge pull request #11 from DLTech21/dev

Dev
This commit is contained in:
Donal 2020-10-08 16:16:29 +08:00 committed by GitHub
commit 293c0b6265
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 116 additions and 7 deletions

View File

@ -33,7 +33,8 @@
"jszip-utils": "^0.1.0",
"sm-crypto": "^0.2.1",
"vue": "^2.6.11",
"web-streams-polyfill": "^2.1.1"
"web-streams-polyfill": "^2.1.1",
"x2js": "^3.4.0"
},
"devDependencies": {
"@vue/cli-plugin-babel": "~4.5.0",

View File

@ -8,6 +8,13 @@
@change="fileChanged">
</div>
<div class="upload-icon" @click="uploadPdfFile">
<div class="upload-icon">PDF2OFD</div>
<font-awesome-icon icon="cloud-upload-alt"/>
<input type="file" ref="pdfFile" class="hidden" accept=".pdf"
@change="pdfFileChanged">
</div>
<div style="display: flex;align-items: center" v-if="ofdObj">
<div class="upload-icon" style="margin-left: 10px" @click="downPdf" v-if="ofdBase64">
下载PDF
@ -155,6 +162,7 @@ export default {
name: 'HelloWorld',
data() {
return {
pdfFile: null,
ofdBase64: null,
loading: false,
pageIndex: 1,
@ -169,6 +177,7 @@ export default {
},
created() {
this.pdfFile = null;
this.file = null;
},
@ -224,6 +233,47 @@ export default {
this.title = title;
},
downOfd(pdfBase64) {
let that = this;
this.loading = true;
this.$axios({
method: "post",
url: "https://51shouzu.xyz/api/ofd/convertOfd",
data: {
pdfBase64,
}
}).then(response => {
that.loading = false;
var binary = atob(response.data.data.replace(/\s/g, ''));
var len = binary.length;
var buffer = new ArrayBuffer(len);
var view = new Uint8Array(buffer);
for (var i = 0; i < len; i++) {
view[i] = binary.charCodeAt(i);
}
var blob = new Blob( [view], null);
var url = URL.createObjectURL(blob);
let link = document.createElement('a')
link.style.display = 'none'
link.href = url
link.setAttribute('download', 'ofd.ofd')
document.body.appendChild(link)
link.click()
}).catch(error => {
console.log(error, "error")
that.$alert('PDF打开失败', error, {
confirmButtonText: '确定',
callback: action => {
this.$message({
type: 'info',
message: `action: ${ action }`
});
}
});
});
},
downPdf() {
let that = this;
this.loading = true;
@ -342,11 +392,27 @@ export default {
this.file = this.$refs.file.files[0];
let ext = this.file.name.replace(/.+\./, "");
if (["ofd"].indexOf(ext) === -1) {
// this.$toast('error', "pngjpgjpeg");
this.$alert('error', '仅支持ofd类型', {
confirmButtonText: '确定',
callback: action => {
this.$message({
type: 'info',
message: `action: ${ action }`
});
}
});
return;
}
if (this.file.size > 5 * 1024 * 1024) {
// this.$toast('error', " < 5M");
if (this.file.size > 20 * 1024 * 1024) {
this.$alert('error', '文件大小需 < 20M', {
confirmButtonText: '确定',
callback: action => {
this.$message({
type: 'info',
message: `action: ${ action }`
});
}
});
return;
}
let that = this;
@ -359,6 +425,47 @@ export default {
this.$refs.file.value = null;
},
uploadPdfFile() {
this.pdfFile = null;
this.$refs.pdfFile.click();
},
pdfFileChanged() {
this.pdfFile = this.$refs.pdfFile.files[0];
let ext = this.pdfFile.name.replace(/.+\./, "");
if (["pdf"].indexOf(ext) === -1) {
this.$alert('error', '仅支持pdf类型', {
confirmButtonText: '确定',
callback: action => {
this.$message({
type: 'info',
message: `action: ${ action }`
});
}
});
return;
}
if (this.pdfFile.size > 20 * 1024 * 1024) {
this.$alert('error', '文件大小需 < 20M', {
confirmButtonText: '确定',
callback: action => {
this.$message({
type: 'info',
message: `action: ${ action }`
});
}
});
return;
}
let that = this;
let reader = new FileReader();
reader.readAsDataURL(this.pdfFile);
reader.onload = function (e) {
let pdfBase64 = e.target.result.split(',')[1];
that.downOfd(pdfBase64);
}
this.$refs.pdfFile.value = null;
},
getOfdDocumentObj(file, screenWidth) {
let that = this;

View File

@ -22,7 +22,6 @@ import {pipeline} from "@/utils/ofd/pipeline";
import JsZip from "jszip";
import {parseStBox, getExtensionByPath, replaceFirstSlash} from "@/utils/ofd/ofd_util";
let parser = require('fast-xml-parser');
import {Jbig2Image} from '../jbig2/jbig2';
import {parseSesSignature} from "@/utils/ofd/ses_signature_parser";
@ -113,9 +112,11 @@ export const getDocument = async function ([zip, doc, docRoot, stampAnnot]) {
if (annotations.indexOf(doc) === -1) {
annotations = `${doc}/${annotations}`;
}
if (zip.files[annotations]) {
annotations = await getJsonFromXmlContent(zip, annotations);
array = array.concat(annotations['json']['ofd:Annotations']['ofd:Page']);
}
}
const annotationObjs = await getAnnotations(annoBase, array, doc, zip)
return [zip, doc, documentObj, stampAnnot, annotationObjs];
}