Try the following Python code, but replace usage of SignDigest
with your own code that contacts Amazon.
doc = PDFDoc(in_docpath)
doc.InitSecurityHandler()
page1 = doc.GetPage(1)
certification_sig_field = doc.CreateDigitalSignatureField(in_cert_field_name)
widgetAnnot = SignatureWidget.Create(doc, Rect(143, 287, 219, 306), certification_sig_field)
page1.AnnotPushBack(widgetAnnot)
# (OPTIONAL) Add an appearance to the signature field.
img = Image.Create(doc.GetSDFDoc(), in_appearance_image_path)
widgetAnnot.CreateSignatureAppearance(img)
##### The following section of sample code inside this function is mostly new and pertains to the custom signing APIs.
# Create a digital signature dictionary inside the digital signature field, in preparation for signing.
certification_sig_field.CreateSigDictForCustomCertification("Adobe.PPKLite",
DigitalSignatureField.e_ETSI_CAdES_detached if in_PAdES_signing_mode is True else DigitalSignatureField.e_adbe_pkcs7_detached,
7500) # 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.
# ... or, if you want to apply a normal non-certification signature, use CreateSigDictForSigning instead.
# (OPTIONAL) Add more information to the signature dictionary.
certification_sig_field.SetLocation("Vancouver, BC")
certification_sig_field.SetReason("Document certification.")
certification_sig_field.SetContactInfo("www.pdftron.com")
# Set the signing time in the signature dictionary, if no secure embedded timestamping support is available from your signing provider.
current_date = Date()
current_date.SetCurrentTime()
certification_sig_field.SetSigDictTimeOfSigning(current_date)
doc.Save(in_outpath, SDFDoc.e_incremental)
# Digest the relevant bytes of the document in accordance with ByteRanges surrounding the signature.
digest = certification_sig_field.CalculateDigest(in_digest_algorithm_type)
# At this point, you can do your custom signing.
#out_signature = DigitalSignatureField.SignDigest(digest, in_private_key_file_path, in_keyfile_password, True, in_digest_algorithm_type)
# With buffer overload
out_signature = []
private_key_buf = []
private_key_file = MappedFile(in_private_key_file_path)
private_key_file_sz = private_key_file.FileSize()
private_key_file_reader = FilterReader(private_key_file)
private_key_buf = private_key_file_reader.Read(private_key_file_sz)
out_signature = DigitalSignatureField.SignDigest(digest, private_key_buf, in_keyfile_password, True, in_digest_algorithm_type)
# Write the signature to the document.
doc.SaveCustomSignature(out_signature, certification_sig_field, in_outpath)