Invalid ByteRangeSize while creating signature dictionary for custom certification

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.

Hi there,

Thank you for reaching out to Apryse forums,

Here is an example of custom signing with HSM:

Some users had success increasing the byte range size:

Best regards,
Kevin Kim

Thanks, I already saw the first example on custom signing with HSM and I’m following that.
I checked the second topic you mentioned above but can’t find something to solve my issue specifically. I tried passing a huge number to the function as the last parameter (as they did) but the issue persists:
Exception:
Message: Invalid ByteRange size.
Conditional expression: byte_range_sz == 4
Version : 10.7.0-e29306f07d
Platform : OSX
Architecture : Arm
Filename : DigitalSignatureField.cpp
Function : GetByteRanges
Linenumber : 122

Hi,

The number is meant to represent the amount of bytes the signature will take, not relative to the size of file. Have you tried just setting it to 7500, do you still get the exception then?