Replacing Text |
Here we modify the document as it is read - searching and replacing some words.
We read a DOCX file and pull out all of the text runs. We go through each of the runs changing some of the words. Finally we save the output.
string src = TestEnvironment.FixturePath("MaryLamb.docx"); string dst = TestEnvironment.OutputPath("ScaryMary.pdf"); Doc doc = new Doc(); doc.SetFile(src); List<TextRunFrame> runs = new List<TextRunFrame>(); doc.DocumentFrame.Scan((f) => { if (f is TextRunFrame) runs.Add((TextRunFrame)f); }); foreach (TextRunFrame run in runs) run.Text = run.Text.Replace("lamb", "leopard"); doc.SaveAs(dst);