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

Free Support Forum - aspose.com

Using JoinRunsWithSameFormatting Code Index Error

Hi,

When converting Word document to pdf, we do the replace operation. However, the “xxx” code you suggested to us previously caused an index error.

The sample project is attached.YG6443.zip (9.3 MB)

@srmbimser

Thanks for your inquiry. Please use FindReplaceOptions.Direction property as Backward to fix this issue. Hope this helps you.

public static void ReplaceWithEvaluator(Aspose.Words.Document wordDoc, string OldValue, string NewValue, bool withLanguage)
{
    ReplaceEval myReplaceEval = new ReplaceEval();
    myReplaceEval.ReplaceText = NewValue.Replace("\n", "");
    myReplaceEval.WithLang = withLanguage;
    myReplaceEval.OldValue = OldValue;
    FindReplaceOptions options = new FindReplaceOptions();
    options.ReplacingCallback = myReplaceEval;
    options.Direction = FindReplaceDirection.Backward;
    wordDoc.Range.Replace(new System.Text.RegularExpressions.Regex(@"\<" + OldValue + @"\>"), "", options);
}

Thanks for your answer. The problem has improved, but can this cause another error?

@srmbimser

Thanks for your inquiry. No, this will not cause any issue. Please let us know if you have any more queries.