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

Free Support Forum - aspose.com

Lock/Unlock Checkbox in Text Field properties to prevent the Pdf file from Editing

Hi Team,
I’m looking for a way to lock and unlock the checkbox in Text field properties to prevent the pdf from editing. please find the Src code and do the needful.TextField.zip (374.0 KB)

Thanks,
Swaran S

@Swaran,

As your query is related to Aspose.PDF for Java API, I am moving your thread in Aspose.PDF forum where you’ll be guided appropriately.

@Swaran

Please try using the below code snippet in order to lock all form fields using JavaScript:

Document doc = new Document(dataDir + "input.pdf");
String js = "for (var i = 0; i < numFields; i += 1) { var fName = getNthFieldName(i); getField(fName).readonly = true; }";
PdfAction action = new JavascriptAction(js);
doc.setOpenAction(action);
doc.save(dataDir + "locked.pdf");

You can also use Flatten() method in order to lock the form fields. Please feel free to let us know in case you need further assistance.

Hi Team,
Already tried with flatten fields and it’s working fine, kindly suggest a way to unlock/unflatten the fields in pdf to make sure the fields are visible once again.

@Swaran

You can set the read-only property to false in JavaScript in order to unlock the form fields:

String js = "for (var i = 0; i < numFields; i += 1) { var fName = getNthFieldName(i); getField(fName).readonly = false; }";

Please feel free to let us know in case you face any issue.