|
@@ -228,6 +228,66 @@ class CPDFWorker {
|
|
|
messageHandler.on('GetSignatures', (data) => {
|
|
|
return getSignatures(data)
|
|
|
})
|
|
|
+ messageHandler.on('AddSignature', async (data) => {
|
|
|
+ const doc = data.doc
|
|
|
+ const pagePtr = data.pagePtr.pagePtr
|
|
|
+ const buf = await convertFileToBuffer(data.certFile)
|
|
|
+
|
|
|
+ ComPDFKitJS.opened_cert[0] = buf
|
|
|
+ const pass = stringToNewUTF8('ComPDFKit')
|
|
|
+ const res = Module._GetX509ByPKCS12Cert(0, buf.length, pass)
|
|
|
+ console.log(res)
|
|
|
+ const subject = []
|
|
|
+ for (let i = 0; i < 7; i++) {
|
|
|
+ Module._GetSignSubject(res, i)
|
|
|
+ subject.push(U8StringData)
|
|
|
+ }
|
|
|
+ const rect = {
|
|
|
+ left: 200,
|
|
|
+ top: 70,
|
|
|
+ right: 270,
|
|
|
+ bottom: 100
|
|
|
+ }
|
|
|
+
|
|
|
+ const annotPtr = Module._CreateWidget(doc, pagePtr, 6)
|
|
|
+ setAnnotCreationDate({
|
|
|
+ annotPtr,
|
|
|
+ date: new Date()
|
|
|
+ })
|
|
|
+
|
|
|
+ setAnnotRect({
|
|
|
+ pagePtr,
|
|
|
+ annotPtr,
|
|
|
+ rect
|
|
|
+ })
|
|
|
+
|
|
|
+ Module._UpdateFormAp(annotPtr)
|
|
|
+
|
|
|
+
|
|
|
+ const signaturePtr = Module._InitSignature2(annotPtr)
|
|
|
+
|
|
|
+ DataArray = []
|
|
|
+ Module._SaveDocumentByStream(doc, 2)
|
|
|
+
|
|
|
+ const addResult = Module._AddSignSaveDocument(doc, signaturePtr, res)
|
|
|
+ console.log(addResult)
|
|
|
+
|
|
|
+ let pdfData = []
|
|
|
+ for (let i = 0; i < DataArray.length; i++) {
|
|
|
+ let subArray = new Uint8Array(DataArray[i])
|
|
|
+ pdfData.push(subArray)
|
|
|
+ }
|
|
|
+ const blobData = new Blob(pdfData, { type: "application/pdf" })
|
|
|
+ const buffer = await convertFileToBuffer(blobData)
|
|
|
+ const length = ComPDFKitJS.opened_files.length
|
|
|
+ ComPDFKitJS.opened_files[length] = buffer
|
|
|
+ const newDoc = Module._InitDocument()
|
|
|
+ const passwordPtr = stringToNewUTF8('')
|
|
|
+ Module._LoadDocumentByStream(newDoc, length, buffer.length, passwordPtr)
|
|
|
+
|
|
|
+ const modifyResult = Module._AddSignModifyDocument(signaturePtr, res, 1, ComPDFKitJS.opened_files[1].length)
|
|
|
+ console.log(modifyResult)
|
|
|
+ })
|
|
|
|
|
|
messageHandler.on('PushRenderTask', (data) => {
|
|
|
const { pagePtr, scale, left, right, bottom, top } = data
|