Product:
Product Version: 10.2.3
Please give a brief summary of your issue:
I’m trying to add a digital signature to a pdf and save it with all its annotations and the digital signature. I can sign it do all the annotations I want and then add the digital signature at the end when I want to save it, but the downloaded file doesn’t contain signatures or it has some weird distortion. It will have all the other annotations display correctly but signatures just don’t show up as expected.
Please describe your issue and provide steps to reproduce it:
Code that I’m using to digital sign and download
async function saveDocumentCertified() {
const { PDFNet, documentViewer, annotationManager } = INSTANCE.Core;
await PDFNet.initialize();
const xfdfString = await annotationManager.exportAnnotations({widgets: false, fields: true, links: false});
await PDFNet.runWithCleanup(async () => {
const doc = await documentViewer.getDocument().getPDFDoc();
const fdfDoc = await PDFNet.FDFDoc.createFromXFDF(xfdfString);
await doc.fdfMerge(fdfDoc);
await doc.flattenAnnotations(false);
await doc.initSecurityHandler();
await doc.lock();
const page1 = await doc.getPage(1);
const certification_sig_field = await doc.createDigitalSignatureField("CertSig");
const widgetAnnot = await PDFNet.SignatureWidget.createWithDigitalSignatureField(doc, new PDFNet.Rect(0, 100, 200, 150), certification_sig_field);
await page1.annotPushBack(widgetAnnot);
await certification_sig_field.setDocumentPermissions(PDFNet.DigitalSignatureField.DocumentPermissions.e_no_changes_allowed);
await certification_sig_field.certifyOnNextSaveFromURL('PATH_TO_PFX', 'PASSWORD');
await certification_sig_field.setLocation('SOMEWHERE');
await certification_sig_field.setReason('Document certified.');
await certification_sig_field.setContactInfo('somewhere contact info');
// Set permissions
const securityHandler = await PDFNet.SecurityHandler.createDefault();
await securityHandler.setPermission(PDFNet.SecurityHandler.Permission.e_doc_modify, false);
await securityHandler.setPermission(PDFNet.SecurityHandler.Permission.e_assemble_doc, false);
await doc.setSecurityHandler(securityHandler);
const docBuffer = await doc.saveMemoryBuffer(PDFNet.SDFDoc.SaveOptions.e_compatibility);
const docBlob = new Blob([docBuffer], {
type: 'application/pdf',
});
// file-saver package
saveAs(docBlob, 'output.pdf');
})
}
How it looks in the web viewer
How it looks after downloading