Thursday, April 2, 2015

Help, to set all formfield readonly in pdf

Not a hard thing.Here is an article exactly helps you ......


How to set read-only fields on a form.


Just download this free PDF API ,add the reference to your project and add the following code .



PdfDocument doc = new PdfDocument();
doc.LoadFromFile("FormField.pdf");

PdfFormWidget widget = doc.Form as PdfFormWidget;

for (int i = 0; i < widget.FieldsWidget.List.Count; i++)
{
PdfField f = widget.FieldsWidget.List[i] as PdfField;
if (f.Name == "username")
{
PdfTextBoxFieldWidget textboxField = f as PdfTextBoxFieldWidget;
textboxField.Text = "Sky.Luo";
}
f.Flatten = true;
f.ReadOnly = true;
}
doc.SaveToFile("FormFieldEdit.pdf");
System.Diagnostics.Process.Start("FormFieldEdit.pdf");





No comments:

Post a Comment