This is the code snippet that reproduces the error:
RadFlowDocument flowDocument = new RadFlowDocument();
RadFlowDocumentEditor editor = new RadFlowDocumentEditor(flowDocument);
Bookmark bookmark = new Bookmark(flowDocument, "Name");
editor.InsertInline(bookmark.BookmarkRangeStart);
Table table = editor.InsertTable(1, 2);
TableCell cell1 = table.Rows[0].Cells[0];
Paragraph cell_paragraph1 = cell1.Blocks.AddParagraph();
editor.MoveToParagraphStart(cell_paragraph1);
editor.InsertText("cell content 01");
TableCell cell2 = table.Rows[0].Cells[1];
Paragraph cell_paragraph2 = cell2.Blocks.AddParagraph();
editor.MoveToParagraphStart(cell_paragraph2);
editor.InsertText("cell content 02");
editor.MoveToTableEnd(table);
editor.InsertInline(bookmark.BookmarkRangeEnd);
RadFlowDocument newFlowDocument = new RadFlowDocument();
RadFlowDocumentEditor editor02 = new RadFlowDocumentEditor(newFlowDocument);
editor.InsertDocument(flowDocument);
Workaround: Insert one bookmark before the table and another one after the table:
RadFlowDocument flowDocument = new RadFlowDocument();
RadFlowDocumentEditor editor = new RadFlowDocumentEditor(flowDocument);
//Bookmark bookmark = new Bookmark(flowDocument, "Name");
//editor.InsertInline(bookmark.BookmarkRangeStart);
editor.InsertBookmark("before");
Table table = editor.InsertTable(1, 2);
TableCell cell1 = table.Rows[0].Cells[0];
Paragraph cell_paragraph1 = cell1.Blocks.AddParagraph();
editor.MoveToParagraphStart(cell_paragraph1);
editor.InsertText("cell content 01");
TableCell cell2 = table.Rows[0].Cells[1];
Paragraph cell_paragraph2 = cell2.Blocks.AddParagraph();
editor.MoveToParagraphStart(cell_paragraph2);
editor.InsertText("cell content 02");
editor.MoveToTableEnd(table);
editor.InsertBookmark("after");
//editor.InsertInline(bookmark.BookmarkRangeEnd);
RadFlowDocument newFlowDocument = new RadFlowDocument();
RadFlowDocumentEditor editor02 = new RadFlowDocumentEditor(newFlowDocument);
editor.InsertDocument(flowDocument);
Use the code for inserting the code:
static void Main(string[] args)
{
Telerik.Windows.Documents.Flow.Model.RadFlowDocument templateDocument = GetDocument("Template.rtf");
Telerik.Windows.Documents.Flow.Model.RadFlowDocument contentDocument = GetDocument("Content.rtf");
InsertDocumentOptions options = new InsertDocumentOptions();
options.ConflictingStylesResolutionMode = ConflictingStylesResolutionMode.RenameSourceStyle;
options.InsertLastParagraphMarker = true;
RadFlowDocumentEditor editor = new RadFlowDocumentEditor(templateDocument);
editor.InsertDocument(contentDocument, options);
string mergedDocumentFilePath ="MergeDocumentsWithWordsProcessing.rtf";
File.Delete(mergedDocumentFilePath);
WriteDocToFile(templateDocument, mergedDocumentFilePath);
}
private static Telerik.Windows.Documents.Flow.Model.RadFlowDocument GetDocument(string rtfFilePath)
{
Telerik.Windows.Documents.Flow.Model.RadFlowDocument document = null;
var rtfImporter = new Telerik.Windows.Documents.Flow.FormatProviders.Rtf.RtfFormatProvider();
using (Stream stream = File.OpenRead(rtfFilePath))
{
document = rtfImporter.Import(stream);
}
return document;
}
private static void WriteDocToFile(Telerik.Windows.Documents.Flow.Model.RadFlowDocument doc, string filename)
{
var rtfExporter = new Telerik.Windows.Documents.Flow.FormatProviders.Rtf.RtfFormatProvider();
string rtfText = rtfExporter.Export(doc);
File.WriteAllText(filename, rtfText);
Process.Start(filename);
}
Observed result: The After spacing is reset
Expected result: keep the style settings from the original documents.
Converting some DocX files to PDF format with page numbering leads to incorrect formatting in the exported PDF:
Input DocX:
Output PDF:
Original DOCX document:
Exported DOCX document:
Workaround:
Telerik.Windows.Documents.Flow.Model.RadFlowDocument document;
Telerik.Windows.Documents.Flow.FormatProviders.Docx.DocxFormatProvider docXprovider = new Telerik.Windows.Documents.Flow.FormatProviders.Docx.DocxFormatProvider();
using (Stream input = File.OpenRead("PT1987 VU22888 Moodle Specification List [2024032716].docx"))
{
document = docXprovider.Import(input);
}
string normalStyleId = BuiltInStyleNames.NormalStyleId;
Style normalStyle = document.StyleRepository.AddBuiltInStyle(normalStyleId);
normalStyle.ParagraphProperties.SpacingAfter.LocalValue = 0;
normalStyle.ParagraphProperties.LineSpacing.LocalValue = 1;
Import the following HTML content:
<ol type="a">
<li>
<div><p>WordsProcessing</p>
</div></li>
<li>
<div>
<p>SpreadProcessing</p>
</div>
</li>
<li>
<div>
<p>PdfProcessing</p>
</div>
</li>
</ol>
The following error occurs:
When exporting a DOCX file to PDF format, the following error message occurs:
PdfFormatProvider: Table cells are exported with the wrong width when the table is nested in another table and the cells of the nested one have a preferred width set to 100%.
Workaround: Clear the cell PreferredWidth property.