|
@@ -567,7 +567,7 @@ class ComPDFKitViewer {
|
|
|
annotationData = [annotationData]
|
|
|
}
|
|
|
for (let i = 0; i < annotationData.length; i++) {
|
|
|
- annotationData[i].type = type
|
|
|
+ !annotationData[i].type && (annotationData[i].type = type)
|
|
|
const annotation = this.#formatAnnotation(annotationData[i])
|
|
|
annotations.push(annotation)
|
|
|
}
|
|
@@ -846,6 +846,7 @@ class ComPDFKitViewer {
|
|
|
if (annotation.replies?.length) {
|
|
|
for (const reply of annotation.replies) {
|
|
|
reply.name = reply.name || uuidv4()
|
|
|
+ reply.mainName = reply.mainName || annotation.name
|
|
|
reply.contents = reply.content
|
|
|
delete reply.content
|
|
|
reply.date = parseAdobePDFTimestamp(rawAnnotation.recentlyModifyDate || rawAnnotation.date || rawAnnotation.creationdate)
|
|
@@ -1083,18 +1084,37 @@ class ComPDFKitViewer {
|
|
|
}
|
|
|
});
|
|
|
if (this.webviewerServer) {
|
|
|
- const annotationsXml = parseAnnotationFromXml(source)
|
|
|
+ const formData = new FormData();
|
|
|
+ formData.append('xfdfFile', data);
|
|
|
+ formData.append('pdfId', this._pdfId);
|
|
|
|
|
|
- const annotations = []
|
|
|
- for (let i = 0; i < annotationsXml.length; i++) {
|
|
|
- const annotation = this.#formatAnnotation(annotationsXml[i])
|
|
|
- annotations.push(annotation)
|
|
|
- }
|
|
|
- if (!annotations.length) return
|
|
|
- this.handleAnnotationChange({
|
|
|
- type: 'add',
|
|
|
- annotation: annotations
|
|
|
+ await fetch(this.optionUrl.webviewBaseUrl + this.optionUrl.uploadAnnotationsUrl, {
|
|
|
+ method: 'POST',
|
|
|
+ headers: {
|
|
|
+ 'Authorization': this._token
|
|
|
+ },
|
|
|
+ body: formData
|
|
|
})
|
|
|
+ .then((response) => response.json())
|
|
|
+ .then((res) => {
|
|
|
+ if (res.code === "200") {
|
|
|
+ const data = res.data
|
|
|
+ this._pdfId = data.pdfId
|
|
|
+ const rawAnnotations = data.annotateJson
|
|
|
+ const annotations = this.convertAnnotation(rawAnnotations)
|
|
|
+ if (annotations) {
|
|
|
+ this.annotations = null
|
|
|
+ // this.emptyAnnotations()
|
|
|
+ this.initAnnotations(annotations, true)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch((error) => {
|
|
|
+ if (error.name !== 'AbortError') {
|
|
|
+ console.log(error)
|
|
|
+ return { error: true, message: error.message }
|
|
|
+ }
|
|
|
+ });
|
|
|
} else {
|
|
|
const xfdfBuffer = new Uint8Array(source)
|
|
|
await this.messageHandler.sendWithPromise('XFDFImportAnnotations', {
|
|
@@ -3338,7 +3358,7 @@ class ComPDFKitViewer {
|
|
|
const { type, annotation, reply, reviewAnnotState, markedAnnotState } = data
|
|
|
const { pagePtr, annotPtr } = annotation
|
|
|
|
|
|
- const annot = this.annotations[annotation.pageIndex].find(item => item.name === annotation.name)
|
|
|
+ const annot = this.annotations[annotation.pageIndex].find(item => item?.name === annotation.name)
|
|
|
if (!annot) return
|
|
|
let annotateHandles = []
|
|
|
|
|
@@ -3494,7 +3514,7 @@ class ComPDFKitViewer {
|
|
|
author: this.annotator
|
|
|
})
|
|
|
|
|
|
- const replayAnnotation = this.annotations[annotation.pageIndex].find(item => item.name === replyItem.name)
|
|
|
+ const replayAnnotation = this.annotations[annotation.pageIndex].find(item => item?.name === replyItem.name)
|
|
|
replayAnnotation.contents = reply.contents
|
|
|
}
|
|
|
}
|