I searched the Internet for 2 weeks and found interesting solutions to my problem, but nothing gives me an answer.
My goal is to do the following:
I want to find text in a static PDF file and replace this text with another text. I would like to keep the content design. Is it really that hard?
I found a way, but I lost all the information:
using (PdfReader reader = new PdfReader(path)) { StringBuilder text = new StringBuilder(); for (int i = 1; i <= reader.NumberOfPages; i++) { text.Append(PdfTextExtractor.GetTextFromPage(reader, i)); text.Replace(txt_SuchenNach.Text, txt_ErsetzenMit.Text); } return text.ToString(); }
My second attempt was better, but I need fields where I can change the text inside:
string fileNameExisting =path; string fileNameNew = @"C:\TEST.pdf"; using (FileStream existingFileStream = new FileStream(fileNameExisting, FileMode.Open)) using (FileStream newFileStream = new FileStream(fileNameNew, FileMode.Create)) {
This preserves the formatting of the rest of the text and changes only the text. I need a solution for text that is NOT in the text box.
Thanks for all your answers and your help.
source share