When mailmerging a document, with nested mail merge group which starts inside a table and ends outside the table, a NullReferenceException is thrown: "System.NullReferenceException: 'Object reference not set to an instance of an object.' firstParagraphInTemplate was null."
Workaround: move the group end (EndGroup, TableEnd, RangeEnd, or GroupEnd) merge field inside the table where the group starts.
Import/Export of specific documents sets style background color to black.
Workaround: do the following conversion of the document with the Document Processing libraries: originalRtf -> exportedDocx, exportedDocx -> finalRtf. After that processing, the finalRTF file will no longer reproduce the issue when exported.
List's top and bottom margins are not correctly exported.
Workaround: Apply TelerikNormal style to the 'ol' element.
Indent of BodyTextIndent style applied to a paragraph is not respected on export.
Workaround: Remove the applied style.
var p = run.Paragraph;
p.Properties.StyleId = string.Empty;
Importing a document containing a hyperlink (<a>) tag without content extends it over the trailing elements.
For example, importing this HTML:
<a></a>
<p>First paragraph</p>
<p>Second paragraph</p>
<p>Third paragraph</p>
Generates:
Instead of this:
When there is a document (e.g. docx) with hanging indent in a list and this document is imported and then exported to HTML, the text overlaps the bullet as shown in the screenshot.
Merging (with RadFlowDocumentEditor's InsertDocument method) documents containing lists sometimes doesn't properly resolve the ListId properties.
Workaround: Removing the list with bullets resolves the issue as there is only one ListId to pick from:
document.Lists.Remove(1);
Workaround:
var fieldInfo = editor.InsertField("TOC");
fieldInfo.UpdateField();
fieldInfo.IsDirty = true;
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;
}
Run the attached sample project. The available Doc1.docx contains an image place holder with borders around all sides. After inserting an image in the place holder, some of the borders are overlapping with the image:
The expected result is to have the borders around all sides:
When a cell is removed due to having no content its table cell borders are not transferred to neighboring cell.
When a table cell contains a paragraph with no runs it is stripped from the document. However, its table cell borders should be transferred/reapplied to its neighboring cell to maintain consistency.
When a document containing a field without a separator is inserted using the RadFlowDocumentEditor.InsertDocument(*) method, the following error is thrown:
System.InvalidOperationException: 'Start and end inlines should belong to paragraph in one block container.'
Workaround:
static void Main(string[] args)
{
DocxFormatProvider _DocXProvider = new DocxFormatProvider();
string outputFile = $@"..\..\MergedResult.docx";
File.Delete(outputFile);
RadFlowDocument target = _DocXProvider.Import(File.ReadAllBytes(@"..\..\HeaderFooter.docx"));
RadFlowDocument source = _DocXProvider.Import(File.ReadAllBytes(@"..\..\SubHeaderFooter.docx"));
RadFlowDocument contentSource = _DocXProvider.Import(File.ReadAllBytes(@"..\..\ContentOnly.docx"));
MergeHeaders(target, source);
MergeFooters(target, source);
MergeContent(target, source);
MergeContent(target, contentSource);
System.IO.File.WriteAllBytes(outputFile, _DocXProvider.Export(target));
Process.Start(outputFile);
}
private static void MergeContent(RadFlowDocument target, RadFlowDocument source)
{
DocumentElementImporter importer = new DocumentElementImporter(target, source, ConflictingStylesResolutionMode.UseTargetStyle);
foreach (Telerik.Windows.Documents.Flow.Model.Section section in source.Sections)
{
foreach (BlockBase block in section.Blocks)
{
BlockBase importBlock = importer.Import(block);
target.Sections.Last().Blocks.Add(importBlock);
}
}
}
private static void MergeHeaders(RadFlowDocument target, RadFlowDocument source)
{
Header targetHeader = target.Sections.First().Headers.Default;
Header sourceHeader = source.Sections.First().Headers.Default;
DocumentElementImporter importer = new DocumentElementImporter(target, source, ConflictingStylesResolutionMode.UseTargetStyle);
foreach (BlockBase block in sourceHeader.Blocks)
{
BlockBase importedBlock = importer.Import(block);
targetHeader.Blocks.Add(importedBlock);
}
}
private static void MergeFooters(RadFlowDocument target, RadFlowDocument source)
{
Footer targetFooter = target.Sections.First().Footers.Default;
Footer sourceFooter = source.Sections.First().Footers.Default;
DocumentElementImporter importer = new DocumentElementImporter(target, source, ConflictingStylesResolutionMode.UseTargetStyle);
int i = 0;
foreach (BlockBase block in sourceFooter.Blocks)
{
BlockBase importedBlock = importer.Import(block);
targetFooter.Blocks.Insert(i++, importedBlock);
}
}