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

Free Support Forum - aspose.com

HTML form to PDF - make all fields read only

I am using Aspose.PDF to convert HTML to PDF. The HTML has form input elements with values populated.

Is there a way to specify that all fields in the output PDF be made read-only?

I tried below but radio buttons, checkboxes and dropdowns are still editable. How can I make those read-only?

com.aspose.pdf.Form form = document.getForm();
com.aspose.pdf.Field[] fields = form.getFields();
for (com.aspose.pdf.Field field : fields) {
field.setReadOnly(true);
}

Hi Vineet,


Thanks for contacting support.

In order to accomplish your requirements, please try using the following code snippet. In case you still face any issue, please share the resource PDF file.

[Java]

//open
source PDF form
<o:p></o:p>

com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document("c:/pdftest/Original (2).pdf");

// flatten form fields inside PDF document

pdfDocument.flatten();

// save updated document

pdfDocument.save("c:/pdftest/Flattened.pdf");