BoldSignA modern eSignature application with affordable pricing. Sign up today for unlimited document usage!
Hello
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?
Thanks
Dominik
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. loadedForm.SetDefaultAppearance(false); 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 loadedDocument.Save(ms); ms.Position = 0; File.WriteAllBytes("Output_old.pdf", ms.ToArray()); //Close the document loadedDocument.Close(); |
follow the below links for more information,
https://help.syncfusion.com/file-formats/pdf/working-with-forms#trygetfield
https://help.syncfusion.com/file-formats/pdf/working-with-forms
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[2];
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:
https://www.syncfusion.com/kb/8564/how-to-replace-the-existing-text-in-the-pdf-document
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