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;
}
Exception trying to import HTML that contains width with an empty value. For example:
<table width="">
You can add captions to figures, equations, or other objects.
From the Office Open XML File Formats Specification: This element specifies the contents and positioning for captions which can be used to automatically label objects in a WordprocessingML document. A caption is a string that labels an object included in a WordprocessingML document, and typically consists of a string plus a field which numbers this item within a collection of similar objects.
Similar functionality can be achieved using the CustomCodeField:
RadFlowDocumentEditor editor = new RadFlowDocumentEditor(document); using (Stream stream = File.OpenRead("Image1.jpg")) { ImageInline image = editor.InsertImageInline(stream, "jpg"); editor.InsertBookmark("Image", image, image); } editor.InsertBreak(BreakType.LineBreak); editor.InsertText("Figure "); editor.InsertField("SEQ Image", "Update Figure Number");
Make it possible to import HTML file with an external style sheet, without the need to handle the LoadStyleSheetFromUri event in HtmlImportSettings. If the URL is correct the data can be internally downloaded.
The missing feature leads to this unwanted behavior:
As a workaround, you need to apply a custom style (with the desired run properties) and apply it to the content control.
string html = File.ReadAllText("Source.html");
string newHtml = html.Replace("<br>", "[br]");
File.WriteAllText("NewSource.html", newHtml);
using (Stream stream = File.OpenRead("NewSource.html"))
{
HtmlFormatProvider htmlFormatProvider = new HtmlFormatProvider();
flowDocument = htmlFormatProvider.Import(stream);
TxtFormatProvider txtFormatProvider = new TxtFormatProvider();
string text = txtFormatProvider.Export(flowDocument);
string newText = text.Replace("[br]", "\r\n");
}