Free Support Forum - aspose.com

Change font with Apose.word and VB

Hi,

I have an appication where I open up a word document make some changes and save it. One of the things that I am trying to do is search for a word string (fopr example "KPractice") and replace it with a wingding symbol prior to the word. So it would be ("wingding character")Practice. I am using Aspose.word for .net and am programming in VB. Any assistance would be great.

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. Please try using the following code:

// Open document.

Document doc = new Document(@"Test085\in.doc");

// Replace KPractice with Wingdings \x00A3 character.

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

doc.Range.Replace(regex, new ReplaceEvaluator(ReplaceWingdingsCheckboxes), false);

//Save output document.

doc.SaveToPdf(@"Test085\out.pdf");

private static ReplaceAction ReplaceWingdingsCheckboxes(object sender, ReplaceEvaluatorArgs e)

{

// Set replacement.

e.Replacement = "\x00A3";

// We also should change font of the run.

((Run)e.MatchNode).Font.Name = "Wingdings";

// Signal to the replace engine to do replace matched text.

return ReplaceAction.Replace;

}

I think it should be easy for you to translate this code to VB. Please let me know in case of any issues.

Hope this helps.

Best regards,