|
@@ -108,25 +108,26 @@ class CPDFWorker {
|
|
|
Module._ClearDocument(data.doc)
|
|
|
}
|
|
|
|
|
|
- if (!data.fontFile) return true
|
|
|
-
|
|
|
- await new Promise((resolve, reject) => {
|
|
|
- const fileReader = new FileReader()
|
|
|
- fileReader.onload = () => {
|
|
|
- const buf = new Uint8Array(fileReader.result)
|
|
|
-
|
|
|
- ComPDFKitJS.opened_Font[0] = buf
|
|
|
- ComPDFKitJS.opened_FontNames[0] = data.fontName
|
|
|
-
|
|
|
- ComPDFKitJS.opened_DefFont[0] = buf
|
|
|
+ if (data.fontFile) {
|
|
|
+ await new Promise((resolve, reject) => {
|
|
|
+ const fileReader = new FileReader()
|
|
|
+ fileReader.onload = () => {
|
|
|
+ const buf = new Uint8Array(fileReader.result)
|
|
|
+
|
|
|
+ ComPDFKitJS.opened_Font[0] = buf
|
|
|
+ ComPDFKitJS.opened_FontNames[0] = data.fontName
|
|
|
+
|
|
|
+ ComPDFKitJS.opened_DefFont[0] = buf
|
|
|
+
|
|
|
+ resolve(true)
|
|
|
+ }
|
|
|
+ fileReader.onerror = () => {
|
|
|
+ reject(fileReader.error)
|
|
|
+ }
|
|
|
+ fileReader.readAsArrayBuffer(data.fontFile)
|
|
|
+ })
|
|
|
+ }
|
|
|
|
|
|
- resolve(true)
|
|
|
- }
|
|
|
- fileReader.onerror = () => {
|
|
|
- reject(fileReader.error)
|
|
|
- }
|
|
|
- fileReader.readAsArrayBuffer(data.fontFile)
|
|
|
- })
|
|
|
const doc = Module._InitDocument()
|
|
|
|
|
|
return doc
|
|
@@ -229,12 +230,88 @@ class CPDFWorker {
|
|
|
return getSignatures(data)
|
|
|
})
|
|
|
messageHandler.on('CreateSignatureAP', async (data) => {
|
|
|
- const { annotPtr } = data
|
|
|
+ const rect = data.rect
|
|
|
+
|
|
|
+ const newDoc = Module._InitDocument()
|
|
|
+ const a = Module._CreateDocument(newDoc)
|
|
|
+ console.log(count)
|
|
|
+ Module._InsertPage(newDoc, 0, 595, 842)
|
|
|
+ const count = Module._GetPageCount(newDoc)
|
|
|
+ console.log(count)
|
|
|
+ const pagePtr = Module._GetPage(newDoc, 0)
|
|
|
+ const annotPtr = Module._CreateWidget(newDoc, pagePtr, 6)
|
|
|
+ setAnnotCreationDate({
|
|
|
+ annotPtr,
|
|
|
+ date: new Date()
|
|
|
+ })
|
|
|
+
|
|
|
+ setAnnotRect({
|
|
|
+ pagePtr,
|
|
|
+ annotPtr,
|
|
|
+ rect
|
|
|
+ })
|
|
|
+
|
|
|
+ Module._UpdateFormAp(annotPtr)
|
|
|
+
|
|
|
const content = stringToNewUTF8('名称:数字签名\n时间:2024.04.21\n原因:我是文件的所有者哈哈哈哈哈哈')
|
|
|
const text = stringToNewUTF8('我是数字签名')
|
|
|
const res = Module._UpdateApWithDigitalSigConfig(annotPtr, content, false, false, false, text, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
|
|
|
console.log(res)
|
|
|
+
|
|
|
+ const { width, height } = rect
|
|
|
+ let pixelNum = width * height
|
|
|
+
|
|
|
+ let imageBytes = pixelNum * 4
|
|
|
+ let imageptr = _malloc(imageBytes)
|
|
|
+ for (var i = 0; i < pixelNum; i++) {
|
|
|
+ Module.HEAP32[imageptr / 4 + i] = 0
|
|
|
+ }
|
|
|
+
|
|
|
+ Module._RenderAnnot(annotPtr, width, height, imageptr, 0)
|
|
|
+ let imageArray = new Uint8Array(imageBytes)
|
|
|
+ for (var i = 0; i < imageBytes; i += 4) {
|
|
|
+ //bgra 转 rgba
|
|
|
+ imageArray[i] = Module.HEAPU8[imageptr + i + 2]
|
|
|
+ imageArray[i + 1] = Module.HEAPU8[imageptr + i + 1]
|
|
|
+ imageArray[i + 2] = Module.HEAPU8[imageptr + i]
|
|
|
+ imageArray[i + 3] = Module.HEAPU8[imageptr + i + 3]
|
|
|
+ }
|
|
|
+ _free(imageptr)
|
|
|
+ return imageArray
|
|
|
})
|
|
|
+
|
|
|
+ messageHandler.on('TestAddSignature', async (data) => {
|
|
|
+ const doc = data.doc
|
|
|
+ const buf = await convertFileToBuffer(data.certFile)
|
|
|
+ ComPDFKitJS.opened_cert[0] = buf
|
|
|
+ const pass = stringToNewUTF8('ComPDFKit')
|
|
|
+ const certPtr = Module._GetX509ByPKCS12Cert(0, buf.length, pass)
|
|
|
+
|
|
|
+ const signaturePtr = Module._InitSignature2(annotPtr)
|
|
|
+
|
|
|
+ DataArray = []
|
|
|
+ Module._SaveDocumentByStream(doc, 2)
|
|
|
+
|
|
|
+ const addResult = Module._AddSignSaveDocument(doc, signaturePtr, certPtr)
|
|
|
+ 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('AddSignature', async (data) => {
|
|
|
const doc = data.doc
|
|
|
const pagePtr = data.pagePtr.pagePtr
|
|
@@ -292,8 +369,10 @@ class CPDFWorker {
|
|
|
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)
|
|
|
+ const modifyResult = Module._AddSignModifyDocument(signaturePtr, res, 1, ComPDFKitJS.opened_files[1].length)
|
|
|
+ console.log(modifyResult)
|
|
|
+
|
|
|
+ return blobData
|
|
|
})
|
|
|
|
|
|
messageHandler.on('PushRenderTask', (data) => {
|
|
@@ -2526,7 +2605,7 @@ async function getSignatures({
|
|
|
|
|
|
const fileLength = ComPDFKitJS.opened_files[0].length
|
|
|
const signerResult = Module._VerifySigner(signaturePtr, signerPtr, 0, fileLength)
|
|
|
-
|
|
|
+ console.log('signerResult', signerResult)
|
|
|
const signatureResult = Module._VerifyDocument(doc, signaturePtr, 0, fileLength)
|
|
|
if (signatureResult === 1) {
|
|
|
signer.isSignVerified = true
|