none
Create RTF document

    Question

  • Hi All,

    I want to create the RTF document using c#. I have used the OpenXml to create the office document docx. 

    Is it possible to use same for RTF ?

    Please share anyone knows anything regarding the RTF creation.

    Thanks !

     

     

    • Déplacé CoolDadTxMVP lundi 7 mai 2018 14:08 Office related
    lundi 7 mai 2018 05:38

Toutes les réponses

  • Hi shital,

    For crating RTF document, I suggest you refer link below:

    #How to create RTF document in C# (without MS Word installed) - Step by Step

    https://code.msdn.microsoft.com/office/How-to-create-RTF-document-2e78819c

    Best Regards,

    Tao Zhou


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    mardi 8 mai 2018 06:46
    Modérateur
  • Hi,

    Check out the following code:

    using Spire.Doc;
    using Spire.Doc.Documents;
    
    namespace CreateRTF
    {
        class Program
        {
            static void Main(string[] args)
            {
                Document doc = new Document();
                Paragraph para = doc.AddSection().AddParagraph();
    
                var rtfCode = @"{\rtf1\deff0{\fonttbl{\f0 Calibri;}{\f1 Times New Roman;}{\f2 Arial;}}{\colortbl ;\red0\green0\blue255 ;\red0\green0\blue0 ;}{\*\defchp \f1}{\*\listoverridetable}{\stylesheet {\ql\f1 Normal;}{\*\cs1\f1 Default Paragraph Font;}{\*\cs2\sbasedon1\f1 Line Number;}{\*\cs3\ul\f1\cf1\ulc1 Hyperlink;}{\*\ts4\tsrowd\f1\ql\trautofit1\tscellpaddfl3\tscellpaddl108\tscellpaddfr3\tscellpaddr108\tsvertalt\cltxlrtb Normal Table;}{\*\ts5\tsrowd\sbasedon4\f1\ql\trbrdrt\brdrs\brdrw10\trbrdrl\brdrs\brdrw10\trbrdrb\brdrs\brdrw10\trbrdrr\brdrs\brdrw10\trbrdrh\brdrs\brdrw10\trbrdrv\brdrs\brdrw10\trautofit1\tscellpaddfl3\tscellpaddl108\tscellpaddfr3\tscellpaddr108\tsvertalt\cltxlrtb Table Simple 1;}}\nouicompat\splytwnine\htmautsp\sectd\pard\plain\qj{\f2\fs20\cf2 PERETARD GAN conc.}{\f2\fs20\cf2  ist ein faseraffiner Retarder mit migrierenden Eigenschaften f\u252\'fcr F\u228\'e4rbungen von Polyacrylnitrilfasern mit basischen Farbstoffen.}\f2\fs20\par\pard\plain\qj\f2\fs20\par\pard\plain\qj{\f2\fs20\cf2 Das Produkt ist kein permanenter Retarder. }{\f2\fs20\cf2 PERETARD GAN conc.}{\f2\fs20\cf2  wird w\u228\'e4hrend der F\u228\'e4rbung bei Kochtemperatur von den Farbstoffen verdr\u228\'e4ngt, so dass ein vollst\u228\'e4ndiger Badauszug erreicht wird. Durch Zusatz von Glaubersalz kann die Egalisierwirkung noch erh\u246\'f6ht werden.}\f2\fs20\par\pard\plain\qj\f2\fs20\par\pard\plain\qj{\f2\fs20\cf2 Das Nuancieren bei Kochtemperatur erfordert einen abgestimmten, weiteren Zusatz von }{\f2\fs20\cf2 PERETARD GAN conc}{\f2\fs20\cf2 .}{\f2\fs20\cf2  Eine \u220\'dcberdosierung sollte vermieden werden.}\f2\fs20\par\pard\plain\qj\f2\fs20\par\pard\plain\qj{\f2\fs20\cf2 Kationische Farbstoffe neigen zum Absetzen an den Wandungen der F\u228\'e4rbeanlagen. Dies kann durch einen Zusatz von PERIGEN W 130 verhindert werden.}\f2\fs20\par}";
    
                para.AppendRTF(rtfCode);
                doc.SaveToFile("RTF.rtf", FileFormat.Rtf);
            }
        }
    }
    Note: The above code is based on a free word library named Free Spire.Doc that is available on NuGet. If you dont mind, you can give it a try.

    mercredi 9 mai 2018 06:59
  • Hi shital,

    Have you resovled your issue?

    If you have, I would suggest you share us the solution and mark it as answer.

    If not, please feel free to keep following.

    Best Regards,

    Tao Zhou


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    mardi 22 mai 2018 08:29
    Modérateur