Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.
Mon Jun 24, 2024 7:10 pm
Hi,
Spire.PDF does not include read-only form fields with this loop;
- Code: Select all
PdfFormWidget formWidget = pdfObj.Form as PdfFormWidget;
if (formWidget == null)
{
return listOfTags;
}
for (int i = 0; i < formWidget.FieldsWidget.List.Count; i++)
{
PdfField field = formWidget.FieldsWidget.List[i] as PdfField;
....
Is there any workaround to replace read-only field texts?
Thank you
-

djacobs111
-
- Posts: 19
- Joined: Mon Aug 01, 2016 6:13 pm
Tue Jun 25, 2024 3:51 am
Hello,
Thanks for your inquiry.
How did you set the read-only attribute for the form field? Did you use "doc.Form.IsFlatten = true" or "field.ReadOnly = true"? The first method will delete the field and only keep the content in the field, so the code cannot get the field in the result document. The second method will not delete the field, and the code can still get the field. Or you can provide us with your pdf file and we will investigate further. You can upload it here as an attachment or send it to this email address:
[email protected]. Thanks in advance.
Sincerely,
William
E-iceblue support team
-


William.Zhang
-
- Posts: 732
- Joined: Mon Dec 27, 2021 2:23 am
Tue Jun 25, 2024 1:50 pm
Hi William,
Sample document sent via email.
Thank you
-

djacobs111
-
- Posts: 19
- Joined: Mon Aug 01, 2016 6:13 pm
Wed Jun 26, 2024 3:52 am
Hello,
Thanks for you file.
I tested your case with the latest
Spire.PDF Pack(Hot Fix) Version:10.6.25, but did not reproduce the problem you mentioned. I used the following code to read two read-only fields in your document. In addition, I modified the content in the read-only fields. I have uploaded the result document as an attachment for your reference. If the issue still exists, please wirte back to us.
- Code: Select all
PdfDocument pdfDocument = new PdfDocument();
pdfDocument.LoadFromFile("Form_SSA-1696_Page_3.pdf");
PdfFormWidget formWidget = pdfDocument.Form as PdfFormWidget;
for (int i = 0; i < formWidget.FieldsWidget.List.Count; i++)
{
PdfField field = formWidget.FieldsWidget.List[i] as PdfField;
bool readOnly = field.ReadOnly;
// Print the names of read-only fields
if (readOnly)
{
field.ReadOnly = false;
if (field is PdfTextBoxFieldWidget)
{
PdfTextBoxFieldWidget textBoxField = field as PdfTextBoxFieldWidget;
//Get text of textbox
textBoxField.Text = "new text";
}
}
}
pdfDocument.SaveToFile("Res.pdf");
Sincerely,
William
E-iceblue support team
Login to view the files attached to this post.
-


William.Zhang
-
- Posts: 732
- Joined: Mon Dec 27, 2021 2:23 am
Wed Jun 26, 2024 1:31 pm
Hi William,
Thank you for the help. It works now.
-

djacobs111
-
- Posts: 19
- Joined: Mon Aug 01, 2016 6:13 pm
Thu Jun 27, 2024 2:42 am
Hello,
Thanks for your feedback.
I'm glad to hear this news. If you have any other questions, please feel free to write back.
Sincerely,
William
E-iceblue support team
-


William.Zhang
-
- Posts: 732
- Joined: Mon Dec 27, 2021 2:23 am