I have a PDF file which I want to open, replace some text fields which are containing dots (...) with real values and then save the PDF.
Is this possible?
I only found out how to extract text lines, but can I somehow directly edit text fields and then save the PDF again?
Please find the below code snippet to achieve your requirement:
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputStream);
//Get the loaded form.
PdfLoadedForm loadedForm = loadedDocument.Form;
//Set the default appearance.
foreach (PdfLoadedField field in loadedForm.Fields)
if (field is PdfLoadedTextBoxField)
PdfLoadedTextBoxField textbox = field as PdfLoadedTextBoxField;
if (textbox.Text == "...")
textbox.Text = "value";
MemoryStream ms = new MemoryStream();
//Save the document
ms.Position = 0;
//Close the document
follow the below links for more information,
Hi and thanks a lot.
loadedDocument.Form is null for my document, does this mean that it is not well formated?
I can extract text from the same loadedDocument like this:
PdfPageBase page = loadedDocument.Pages;
TextLineCollection lineCollection = new TextLineCollection();
Thank you for sharing the details. If the loaded form is Null, it seems there are no form fields in the PDF document. The extract text API is to extract the text drawn in the PDF document. This will not return the values in the Fields.
If your requirement is to replace the text extracted from the PDF document. Please refer to the below documentation link to achieve the same on you end:
If still you are facing an issue, we request you to share the input document, a simple sample, and steps to replicate the issue on our end. So that we can assist with you further in this