We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Locking form fields using signature


when a document with signature field created by aspose is signed (by user for example in acrobat) the fields are still editable. How can I define which fields should be locked or at least how I force locking of all fields?


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.

pdfDocument = new Document();<o:p></o:p>


// Create a field

SignatureField signatureField = new SignatureField(pdfDocument.getPages().get_Item(1), new Rectangle(100, 200, 300, 300));


Border border = new Border(signatureField);


border.setDash(new Dash(1, 1));



// 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,


thanks, but I meant something different. I dont want to d

When user (using acrobat reader) signs the document using signature field, I want to make all field “readonly”, so no form values can be changed anymore. This has to be done automatically (on user signature) - so no java code. Maybe some javascript? I think the list of fields to be locked should be a property of the signature field?

In my case it would be enough if the whole document were set as readonly. At least, how could I achieve that?


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);


In case of any further assistance, please feel free to contact us.

Best Regards,