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

Free Support Forum - aspose.com

Edit-save and edit again

Hi,

I want to highlight some words in a document and save a page as image. After that, I want to hightlight another word and save page again. But second image is same as the first one (second word is not highlighted).
What is the point I’m missing?

Thank you,

The code is as follows :

Aspose.Words.Document doc = new Aspose.Words.Document(@"…");

Regex regex = new Regex("\bANKARA", RegexOptions.IgnoreCase);
doc.Range.Replace(regex, new ReplaceEvaluatorFindAndHighlight(), false);

Aspose.Words.Saving.ImageSaveOptions imageSaveOptions = new Aspose.Words.Saving.ImageSaveOptions(Aspose.Words.SaveFormat.Png);
imageSaveOptions.PageIndex = 0;
imageSaveOptions.PageCount = 1;
imageSaveOptions.Resolution = 96;
doc.Save(@“c:\temp\test1.png”, imageSaveOptions);

regex = new Regex("\bBURKAY", RegexOptions.IgnoreCase);
doc.Range.Replace(regex, new ReplaceEvaluatorFindAndHighlight(), false);
doc.Save(@“c:\temp\test2.png”, imageSaveOptions);

Hi Huseyin,


Thanks for your inquiry. I believe that calling Document.UpdatePageLayout method before saving to image second time will fix this issue.

Aspose.Words.Document doc = new Aspose.Words.Document(@"…");

Regex regex = new Regex("\\bANKARA", RegexOptions.IgnoreCase);

doc.Range.Replace(regex, new ReplaceEvaluatorFindAndHighlight(), false);

Aspose.Words.Saving.ImageSaveOptions imageSaveOptions = new Aspose.Words.Saving.ImageSaveOptions(Aspose.Words.SaveFormat.Png);

imageSaveOptions.PageIndex = 0;

imageSaveOptions.PageCount = 1;

imageSaveOptions.Resolution = 96;

doc.Save(@"c:\temp\test1.png", imageSaveOptions);

regex = new Regex("\\bBURKAY", RegexOptions.IgnoreCase);

doc.Range.Replace(regex, new ReplaceEvaluatorFindAndHighlight(), false);

doc.UpdatePageLayout();

doc.Save(@"c:\temp\test2.png", imageSaveOptions);


Hope, this helps.

Best regards,
Yes, it fixed my issue.

Thank you for your kind interest.