Hi,
Hi There,
Thanks for contacting support.
In order to lock form fields, so that they cannot be editable by user, you can flatten them by using Flatten() Method provided by Aspose.Pdf for Java. Please check following code snippet and highlighted part in it, where I showed how to flatten all form fields OR only single form field.
Document pdfDocument = new Document();
pdfDocument.getPages().add();
// Create a field
SignatureField signatureField = new SignatureField(pdfDocument.getPages().get_Item(1), new Rectangle(100, 200, 300, 300));
signatureField.setPartialName("signature1");
Border border = new Border(signatureField);
border.setWidth(1);
border.setDash(**new** Dash(1, 1));
signatureField.getCharacteristics().setBorder(java.awt.Color.BLACK);
signatureField.setBorder(border);
// Add field to the document
pdfDocument.getForm().add(signatureField, 1);
signatureField.flatten(); // To Flatten Single Field
pdfDocument.flatten(); // To Flatten All Fields
// Save modified PDF
pdfDocument.save(dataDir + "OutputSignature.pdf");
In case of any further assistance, please feel free to contact us.
Best Regards,
Hi,
Hi There,
Thanks for sharing more details.
However, in Adobe Reader, there is a default option to lock document after signing it (Please check attached screenshot) but you can achieve it by adding Javascript into document which will make all form fields read-only after signing it. Please check following code snippet (and javascript) to make all form fields read-only after signing process.
String js = “for
(var i = 0; i < numFields; i += 1) { var fName = getNthFieldName(i);
getField(fName).readonly = true; }”;
PdfAction action = new JavascriptAction(js);
signatureField.setOnActivated(action);
In case of any further assistance, please feel free to contact us.
Best Regards,