ReplaceAction IReplacingCallback.Replacing(ReplacingArgs e) { // Insert a document after the paragraph, containing the match text. Paragraph para = (Paragraph)e.MatchNode.ParentNode; //InsertDocument(para, subDoc);
Document doc = (Document)e.MatchNode.Document; DocumentBuilder docBuilder = new DocumentBuilder(doc);
// duplicate pattern for next replace use if (this.hasNext) { Paragraph paraClone = (Paragraph)para.Clone(true); para.ParentNode.InsertAfter(paraClone, para); }
// Remove the paragraph with the match text. //para.Remove();
return ReplaceAction.Skip; } }
staticvoidMain(string[] args) { Document doc = new Document("C:\\Dev\\Test\\AsposeTest\\MES dev quote.docx"); DocumentBuilder docBuilder = new DocumentBuilder(doc);
doc.Range.Replace(new Regex("__pattern__"), new InsertAtReplaceHandler("TEST20171214", true), false); doc.Range.Replace(new Regex("__pattern__"), new InsertAtReplaceHandler("TEST20171215", false), false);
doc.Save("C:\\Dev\\Test\\AsposeTest\\MES dev quote.output.pdf"); } } }