Handle import of documents with self-referring styles.
As a workaround, you can go through the RTF document structure of a single file and utilize Regex to resolve the self-referring styles like this:
string rtf = File.ReadAllText("inputFile.rtf");
rtf = FixSelfReferringStyles(rtf);
Telerik.Windows.Documents.Flow.FormatProviders.Rtf.RtfFormatProvider provider = new Telerik.Windows.Documents.Flow.FormatProviders.Rtf.RtfFormatProvider();
var document = provider.Import(rtf);
...
private static string FixSelfReferringStyles(string rtf)
{
string regexString = @"{\\s([0-9]+)[^}]*\\slink([0-9]+)";
var matches = Regex.Matches(rtf, regexString);
foreach (Match match in matches)
{
if (match.Groups[1].Value == match.Groups[2].Value)
{
var oldValue = match.Groups[0].Value;
var newValue = oldValue.Replace(@" \slink" + match.Groups[1].Value, string.Empty);
rtf = rtf.Replace(oldValue, newValue);
}
}
return rtf;
}