We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Replace issue

I have found an issue if you use the Replace function to replace a piece of text in a document with the value of the PageCount property for the document.

AsposeReplaceProblem.zip (291.8 KB)

Please see attached example (the document is in the zip file as well, in a sub folder).

If you choose yes to the question that pops up, it uses the PageCount value and even displays the output of the GetText call which shows the replace has taken place.

However, the saved file does not include the change.

@gregglinnell,

Please call Document.UpdatePageLayout method before saving to PDF. Simple code is as follows:

Document doc = new Document("D:\\AsposeReplaceProblem\\ReplaceDoc.docx");

var options = new Aspose.Words.Replacing.FindReplaceOptions()
{
    FindWholeWordsOnly = false,
    MatchCase = true
};

doc.Range.Replace("{Value}", doc.PageCount.ToString(), options); // does not work
//doc.Range.Replace("{Value}", "1", options); // works

Console.WriteLine(doc.GetText());

doc.UpdatePageLayout();

doc.Save("D:\\AsposeReplaceProblem\\18.10.docx");
doc.Save("D:\\AsposeReplaceProblem\\18.10.pdf");