Selaa lähdekoodia

fix: server模式导入ink问题

wzl 9 kuukautta sitten
vanhempi
commit
2f4ab2db05
2 muutettua tiedostoa jossa 8 lisäystä ja 2 poistoa
  1. 6 1
      packages/core/src/index.js
  2. 2 1
      packages/core/src/ui_utils.js

+ 6 - 1
packages/core/src/index.js

@@ -578,6 +578,7 @@ class ComPDFKitViewer {
 
   #formatRect(annotation) {
     const pageIndex = annotation.page
+    if (!this.pagesPtr[pageIndex]?.height) return
     const { height } = this.pagesPtr[pageIndex]
 
     const rect = annotation.rect.split(',')
@@ -597,6 +598,7 @@ class ComPDFKitViewer {
   #formatCoords(annotation) {
     const formattedCoords = []
     const pageIndex = annotation.page
+    if (!this.pagesPtr[pageIndex]?.height) return
     const { height } = this.pagesPtr[pageIndex]
 
     const coords = annotation.coords.split(',')
@@ -635,6 +637,7 @@ class ComPDFKitViewer {
 
   #formatLinePoints(annotation) {
     const pageIndex = annotation.page
+    if (!this.pagesPtr[pageIndex]?.height) return
     const { height } = this.pagesPtr[pageIndex]
     const linePoints = []
 
@@ -650,6 +653,7 @@ class ComPDFKitViewer {
 
   #formatInkPointes(annotation) {
     const pageIndex = annotation.page
+    if (!this.pagesPtr[pageIndex]?.height) return
     const { height } = this.pagesPtr[pageIndex]
     const inklist = []
 
@@ -1747,6 +1751,7 @@ class ComPDFKitViewer {
   }
 
   #formatRectForBackend(rect, pageIndex) {
+    if (!this.pagesPtr[pageIndex]?.height) return
     const { height } = this.pagesPtr[pageIndex]
     const { left, top: rawTop, right, bottom: rawBottom } = rect
     const top = height - rawTop
@@ -1755,6 +1760,7 @@ class ComPDFKitViewer {
   }
 
   #formatLinePointsForBackend(linePoints, pageIndex) {
+    if (!this.pagesPtr[pageIndex]?.height) return
     const { height } = this.pagesPtr[pageIndex]
     const top = height - linePoints[1]
     const bottom = height - linePoints[3]
@@ -3359,7 +3365,6 @@ class ComPDFKitViewer {
           const annotations = this.annotations[annotation.pageIndex]
           const index = findIndex(annot.name, annotations)
           annot.index = index
-          console.log(index)
 
           annotateHandles.push({
             operate: 'add-annot',

+ 2 - 1
packages/core/src/ui_utils.js

@@ -1225,6 +1225,7 @@ const parseAnnotationFromXml = (xmlString) => {
       if (type === 'ink') {
         const gesture = getPosition(cur)
         if (!gesture) continue
+        !annotation.inklist && (annotation.inklist = {})
         annotation.inklist.gesture = gesture
       }
 
@@ -1258,7 +1259,7 @@ const parseAnnotationFromXml = (xmlString) => {
 
 const getPosition = (element) => {
   let gesture = [];
-  const nodes = element.childNodes[0].childNodes;
+  const nodes = element.children[0].children;
   const nodeList = Array.prototype.slice.call(nodes);
   nodeList.forEach((ele) => {
     if (ele.tagName === 'gesture') {