فهرست منبع

fix: 注释跨页移动修复外观无法添加bug

liutian 2 هفته پیش
والد
کامیت
bf811d613d

+ 1 - 0
packages/core/src/annotation/stamp.js

@@ -138,6 +138,7 @@ export default class Stamp extends Base {
       drawContext.putImageData(imageData, 0, 0)
       imgSrc = canvas.toDataURL("image/png", 1)
     }
+    annotation.imageBase64 = imgSrc
 
     imgEle.src = imgSrc
     this.imgEle = imgEle

+ 6 - 2
packages/core/src/form/signature_fields.js

@@ -119,7 +119,8 @@ export default class SignatureFields extends Base {
     if (signature) {
       this.isDigital = signature.isDigital
     }
-    await this.getSignatureImage()
+    const imgBase64 = await this.getSignatureImage()
+    annotation.imageBase64 = imgBase64
 
     this.annotationContainer.append(this.shapeElement)
     !annotation.isSigned && this.annotationContainer.append(this.tagElement)
@@ -893,6 +894,8 @@ export default class SignatureFields extends Base {
 
       this.annotationContainer.append(this.imgEle)
     }
+
+    return imgSrc
   }
 
   async updateAp(annotPtr) {
@@ -900,6 +903,7 @@ export default class SignatureFields extends Base {
     this.isDigital = false
     this.annotation.isSigned = 1
     this.tagElement.remove()
-    await this.getSignatureImage()
+    const imgBase64 = await this.getSignatureImage()
+    this.annotation.imageBase64 = imgBase64
   }
 }

+ 19 - 2
packages/core/src/worker/compdfkit_worker.js

@@ -633,8 +633,11 @@ class CPDFWorker {
         setAnnotAuthor(annotation)
       }
 
-      if (annotation.operate === 'mod-form') Module._UpdateFormAp(annotation.annotPtr)
-      else Module._UpdateAnnotAp(annotation.annotPtr, 0)
+      if (annotation.operate === 'mod-form' && annotation.type !== 'signatureFields') {
+        Module._UpdateFormAp(annotation.annotPtr)
+      } else {
+        Module._UpdateAnnotAp(annotation.annotPtr, 0)
+      }
     })
 
     messageHandler.on('FlattenPage', (data) => {
@@ -2411,6 +2414,20 @@ function createWidget(doc, pagePtr, annotation) {
   })
 
   Module._UpdateFormAp(annotPtr)
+
+  if (type === 'signatureFields') {
+    const { imageBase64 } = annotation
+    if (imageBase64) {
+      const imageData = convertBase64ToBytes(imageBase64)
+
+      ComPDFKitJS.opened_image = []
+      ComPDFKitJS.opened_image[0] = imageData
+
+      Module._RemoveAP(annotPtr)
+      Module._SetImageStampByStream(annotPtr, 0, imageData.length, 0)
+      Module._SignWithName(annotPtr)
+    }
+  }
   return {
     annotPtr
   }