Unplanned
Last Updated: 10 Apr 2024 13:53 by Benjamin
Benjamin
Created on: 10 Apr 2024 13:53
Category: RichTextEditor
Type: Bug Report
0
RadRichTextEditor: RadDocumentEditor.Insert Fragment resets local paragraph styles of imported document to the global style of the base template

This is the used code snippet:

        static void Main(string[] args)
        {
            Telerik.WinForms.Documents.Model.RadDocument templateDocument = GetDocument("Template.rtf");
            Telerik.WinForms.Documents.Model.RadDocument contentDocument = GetDocument("Content.rtf");

            Telerik.WinForms.Documents.Model.Merging.InsertDocumentOptions options = new Telerik.WinForms.Documents.Model.Merging.InsertDocumentOptions();
            options.ConflictingStylesResolutionMode = Telerik.WinForms.Documents.Model.Merging.ConflictingStylesResolutionMode.RenameSourceStyle;
            options.InsertLastParagraphMarker = true;

            Telerik.WinForms.Documents.Model.RadDocumentEditor templateEditor = new Telerik.WinForms.Documents.Model.RadDocumentEditor(templateDocument);
            templateEditor.InsertFragment(new Telerik.WinForms.Documents.Model.DocumentFragment(contentDocument));

    
            string mergedDocumentFilePath = "MergeDocumentsWithRichTextEditor.rtf";
            File.Delete(mergedDocumentFilePath);
            WriteDocToFile(templateDocument, mergedDocumentFilePath);

        }
        private static Telerik.WinForms.Documents.Model.RadDocument GetDocument(string rtfFilePath)
        {
            Telerik.WinForms.Documents.Model.RadDocument document = null;
            var rtfImporter = new Telerik.WinForms.Documents.FormatProviders.Rtf.RtfFormatProvider();
            using (Stream stream = File.OpenRead(rtfFilePath))
            {
                document = rtfImporter.Import(stream);
            }
            return document;
        }


        private static void WriteDocToFile(Telerik.WinForms.Documents.Model.RadDocument doc, string filename)
        {
            var rtfExporter = new Telerik.WinForms.Documents.FormatProviders.Rtf.RtfFormatProvider();
            string rtfText = rtfExporter.Export(doc);
            File.WriteAllText(filename, rtfText);

            Process.Start(filename);
        }

Observed result: 

Expected result: keep the After spacing as it is in the original documents.

0 comments