Product: pdftron / nodejs
Product Version: 10.7.0
Please give a brief summary of your issue:
(Think of this as an email subject)
Exception invalid byteRange size while trying to use createSigDictForCustomCertification
Please describe your issue and provide steps to reproduce it:
(The more descriptive your answer, the faster we are able to help you)
I am having pdf data stored in memory not a file (Unit8Array), and trying to certify that. When I use the function createSigDictForCustomCertification and pass the last parameter (in_content_size_to_reserve), it throws exception of invalid byterange size (conditional expression: byte_range_sz == 4)
I tried passing the pdfArray.byteLength as the value, pass smaller number, but it didn’t work. My pdfArray byteLength is around 65122. I tried with smaller pdf (10582) but still the same.
What should be passed as the content size exactly ? Is there any specific way to determine that value? Or is it caused by something else ?
Please provide a link to a minimal sample where the issue is reproducible:
(Code snippet where the exception occurs):
const doc = await pdftron.PDFNet.PDFDoc.createFromBuffer(pdfFile)
await doc.initSecurityHandler()
const page1 = await doc.getPage(1)
const certificationField = await doc.createDigitalSignatureField('certificationField')
console.log('certification field has been created')
const widgetAnnot = await pdftron.PDFNet.SignatureWidget.createWithDigitalSignatureField(
doc,
new pdftron.PDFNet.Rect(143, 287, 219, 306),
certificationField,
)
console.log('widgetAnnot has been created')
await page1.annotPushBack(widgetAnnot)
console.log('widgetAnnot has been added')
console.log('size: ', pdfFile.byteLength)
// Create a digital signature dictionary inside the digital signature field, in preparation for signing.
await certificationField.createSigDictForCustomCertification(
"Adobe.PPKLite",
pdftron.PDFNet.DigitalSignatureField.SubFilterType.e_adbe_pkcs7_detached,
pdfFile.byteLength + 1
).catch((error) => {
console.log(`${error.message} during creation`)
}) // For security reasons, set the contents size to a value greater than but as close as possible to the size you expect your final signature to be, in bytes.