Best way to merge two RTF files for DOCX export

  • Hello. I need to insert a program generated RTF formatted string into a RTF document opened by a WPRichText component. Basically I have one document that works as a template, and I need to insert in the middle of it some RTF formatted text. I used to do it successfully like that:

    // loads the first RTF file into WPRichText
    WPRichText1.LoadFromFile('Template.RTF', False, 'RTF');
    // inserts the RTF formatted string at the end of WPRichText1 content
    WPRichText1.SelLength := 0;
    WPRichText1.CPPosition := maxint;
    WPRichText1.FastInsertParagraph;
    WPRichText1.SelectionAsString := rtf_formatted_string;
    WPRichText1.ReformatAll(true,true);"

    This works flawlessly when I save the final document as a RTF file, but when I save it as a DOCX file some fonts get replaced by Times New Roman.

    Is there a better way of inserting a RTF string inside another RTF document?

    Thanks

  • Thank you for your answer, but the problem remains. But I think I found out what it was, and it had nothing to do with RTF merging.

    The problem with fonts being replaced when exporting to DOCX is related to the WPRichText default font (in my case, Arial). If I create a RTF document and a paragraph uses the WPRichText default font, Microsoft Word replaces that font with its default font (Times New Roman) when opening, as if it was plain text.

    I believe this is a bug in the WPTools DOCX reader-writer plugin.