How to copy the format of the text from an RTF string and apply it to text in DOCX format document?
Syncfusion® Essential® DocIO is a .NET Word library used to create, read, edit, and convert Word documents programmatically without Microsoft Word or interop dependencies. Using this library, you can copy the format of the text from an RTF string and apply it to text in DOCX format document using C#.
Steps to copy the format of the text from an RTF string and apply it to text in DOCX format document:
- Create a new .NET Core console application project.
- Install the Syncfusion.DocIO.Net.Core NuGet package as a reference to your project from NuGet.org.
Starting with v16.2.0.x, if you reference Syncfusion® assemblies from trial setup or from the NuGet feed, include a license key in your projects. Refer to the link to learn about generating and registering a Syncfusion® license key in your application to use the components without trail message.
- Include the following namespaces in Program.cs file
C#
using Syncfusion.DocIO.DLS;
using Syncfusion.DocIO;
- Use the following code example to copy the format of the text from an RTF string and apply it to text in DOCX format document.
C#
// RTF format string contains text along with formatting.
string RtfString = "{\\rtf1\\adeflang1025\\ansi\\ansicpg1252\\uc1\\adeff0\\deff0\\stshfdbch0\\stshfloch0\\stshfhich0\\stshfbi0\\deflang1033\\deflangfe1033\\themelang1033\\themelangfe0\\themelangcs0{\\fonttbl{\\f0\\fbidi \\froman\\fcharset0\\fprq2{\\*\\panose 02020603050405020304}Times New Roman;}{\\f1\\fbidi \\fswiss\\fcharset0\\fprq2{\\*\\panose 020b0604020202020204}Arial;}\r\n{\\f2\\fbidi \\fmodern\\fcharset0\\fprq1{\\*\\panose 02070309020205020404}Courier New;}{\\f3\\fbidi \\froman\\fcharset2\\fprq2{\\*\\panose 05050102010706020507}Symbol;}{\\f10\\fbidi \\fnil\\fcharset2\\fprq2{\\*\\panose 05000000000000000000}Wingdings;}\r\n{\\f11\\fbidi \\fmodern\\fcharset128\\fprq1{\\*\\panose 02020609040205080304}MS Mincho{\\*\\falt \\'82\\'6c\\'82\\'72 \\'96\\'be\\'92\\'a9};}{\\f34\\fbidi \\froman\\fcharset0\\fprq2{\\*\\panose 02040503050406030204}Cambria Math;}\r\n{\\f37\\fbidi \\fswiss\\fcharset0\\fprq2{\\*\\panose 020f0502020204030204}Calibri;}{\\f40\\fbidi \\fswiss\\fcharset0\\fprq2{\\*\\panose 020b0604030504040204}Verdana;}{\\f1277\\fbidi \\fmodern\\fcharset128\\fprq1{\\*\\panose 02020609040205080304}@MS Mincho;}\r\n{\\flomajor\\f31500\\fbidi \\froman\\fcharset0\\fprq2{\\*\\panose 02020603050405020304}Times New Roman;}{\\fdbmajor\\f31501\\fbidi \\froman\\fcharset0\\fprq2{\\*\\panose 02020603050405020304}Times New Roman;}\r\n{\\fhimajor\\f31502\\fbidi \\fswiss\\fcharset0\\fprq2{\\*\\panose 020f0302020204030204}Calibri Light;}{\\fbimajor\\f31503\\fbidi \\froman\\fcharset0\\fprq2{\\*\\panose 02020603050405020304}Times New Roman;}\r\n{\\flominor\\f31504\\fbidi \\froman\\fcharset0\\fprq2{\\*\\panose 02020603050405020304}Times New Roman;}{\\fdbminor\\f31505\\fbidi \\froman\\fcharset0\\fprq2{\\*\\panose 02020603050405020304}Times New Roman;}\r\n{\\fhiminor\\f31506\\fbidi \\fswiss\\fcharset0\\fprq2{\\*\\panose 020f0502020204030204}Calibri;}{\\fbiminor\\f31507\\fbidi \\froman\\fcharset0\\fprq2{\\*\\panose 02020603050405020304}Times New Roman;}{\\f1278\\fbidi \\froman\\fcharset238\\fprq2 Times New Roman CE;}\r\n{\\f1279\\fbidi \\froman\\fcharset204\\fprq2 Times New Roman Cyr;}{\\f1281\\fbidi \\froman\\fcharset161\\fprq2 Times New Roman Greek;}{\\f1282\\fbidi \\froman\\fcharset162\\fprq2 Times New Roman Tur;}{\\f1283\\fbidi \\froman\\fcharset177\\fprq2 Times New Roman (Hebrew);}\r\n{\\f1284\\fbidi \\froman\\fcharset178\\fprq2 Times New Roman (Arabic);}{\\f1285\\fbidi \\froman\\fcharset186\\fprq2 Times New Roman Baltic;}{\\f1286\\fbidi \\froman\\fcharset163\\fprq2 Times New Roman (Vietnamese);}{\\f1288\\fbidi \\fswiss\\fcharset238\\fprq2 Arial CE;}\r\n{\\f1289\\fbidi \\fswiss\\fcharset204\\fprq2 Arial Cyr;}{\\f1291\\fbidi \\fswiss\\fcharset161\\fprq2 Arial Greek;}{\\f1292\\fbidi \\fswiss\\fcharset162\\fprq2 Arial Tur;}{\\f1293\\fbidi \\fswiss\\fcharset177\\fprq2 Arial (Hebrew);}\r\n{\\f1294\\fbidi \\fswiss\\fcharset178\\fprq2 Arial (Arabic);}{\\f1295\\fbidi \\fswiss\\fcharset186\\fprq2 Arial Baltic;}{\\f1296\\fbidi \\fswiss\\fcharset163\\fprq2 Arial (Vietnamese);}{\\f1298\\fbidi \\fmodern\\fcharset238\\fprq1 Courier New CE;}\r\n{\\f1299\\fbidi \\fmodern\\fcharset204\\fprq1 Courier New Cyr;}{\\f1301\\fbidi \\fmodern\\fcharset161\\fprq1 Courier New Greek;}{\\f1302\\fbidi \\fmodern\\fcharset162\\fprq1 Courier New Tur;}{\\f1303\\fbidi \\fmodern\\fcharset177\\fprq1 Courier New (Hebrew);}\r\n{\\f1304\\fbidi \\fmodern\\fcharset178\\fprq1 Courier New (Arabic);}{\\f1305\\fbidi \\fmodern\\fcharset186\\fprq1 Courier New Baltic;}{\\f1306\\fbidi \\fmodern\\fcharset163\\fprq1 Courier New (Vietnamese);}\r\n{\\f1390\\fbidi \\fmodern\\fcharset0\\fprq1 MS Mincho Western{\\*\\falt \\'82\\'6c\\'82\\'72 \\'96\\'be\\'92\\'a9};}{\\f1388\\fbidi \\fmodern\\fcharset238\\fprq1 MS Mincho CE{\\*\\falt \\'82\\'6c\\'82\\'72 \\'96\\'be\\'92\\'a9};}\r\n{\\f1389\\fbidi \\fmodern\\fcharset204\\fprq1 MS Mincho Cyr{\\*\\falt \\'82\\'6c\\'82\\'72 \\'96\\'be\\'92\\'a9};}{\\f1391\\fbidi \\fmodern\\fcharset161\\fprq1 MS Mincho Greek{\\*\\falt \\'82\\'6c\\'82\\'72 \\'96\\'be\\'92\\'a9};}\r\n{\\f1392\\fbidi \\fmodern\\fcharset162\\fprq1 MS Mincho Tur{\\*\\falt \\'82\\'6c\\'82\\'72 \\'96\\'be\\'92\\'a9};}{\\f1395\\fbidi \\fmodern\\fcharset186\\fprq1 MS Mincho Baltic{\\*\\falt \\'82\\'6c\\'82\\'72 \\'96\\'be\\'92\\'a9};}\r\n{\\f1618\\fbidi \\froman\\fcharset238\\fprq2 Cambria Math CE;}{\\f1619\\fbidi \\froman\\fcharset204\\fprq2 Cambria Math Cyr;}{\\f1621\\fbidi \\froman\\fcharset161\\fprq2 Cambria Math Greek;}{\\f1622\\fbidi \\froman\\fcharset162\\fprq2 Cambria Math Tur;}\r\n{\\f1625\\fbidi \\froman\\fcharset186\\fprq2 Cambria Math Baltic;}{\\f1626\\fbidi \\froman\\fcharset163\\fprq2 Cambria Math (Vietnamese);}{\\f1648\\fbidi \\fswiss\\fcharset238\\fprq2 Calibri CE;}{\\f1649\\fbidi \\fswiss\\fcharset204\\fprq2 Calibri Cyr;}\r\n{\\f1651\\fbidi \\fswiss\\fcharset161\\fprq2 Calibri Greek;}{\\f1652\\fbidi \\fswiss\\fcharset162\\fprq2 Calibri Tur;}{\\f1653\\fbidi \\fswiss\\fcharset177\\fprq2 Calibri (Hebrew);}{\\f1654\\fbidi \\fswiss\\fcharset178\\fprq2 Calibri (Arabic);}\r\n{\\f1655\\fbidi \\fswiss\\fcharset186\\fprq2 Calibri Baltic;}{\\f1656\\fbidi \\fswiss\\fcharset163\\fprq2 Calibri (Vietnamese);}{\\f1678\\fbidi \\fswiss\\fcharset238\\fprq2 Verdana CE;}{\\f1679\\fbidi \\fswiss\\fcharset204\\fprq2 Verdana Cyr;}\r\n{\\f1681\\fbidi \\fswiss\\fcharset161\\fprq2 Verdana Greek;}{\\f1682\\fbidi \\fswiss\\fcharset162\\fprq2 Verdana Tur;}{\\f1685\\fbidi \\fswiss\\fcharset186\\fprq2 Verdana Baltic;}{\\f1686\\fbidi \\fswiss\\fcharset163\\fprq2 Verdana (Vietnamese);}\r\n{\\f14050\\fbidi \\fmodern\\fcharset0\\fprq1 @MS Mincho Western;}{\\f14048\\fbidi \\fmodern\\fcharset238\\fprq1 @MS Mincho CE;}{\\f14049\\fbidi \\fmodern\\fcharset204\\fprq1 @MS Mincho Cyr;}{\\f14051\\fbidi \\fmodern\\fcharset161\\fprq1 @MS Mincho Greek;}\r\n{\\f14052\\fbidi \\fmodern\\fcharset162\\fprq1 @MS Mincho Tur;}{\\f14055\\fbidi \\fmodern\\fcharset186\\fprq1 @MS Mincho Baltic;}{\\flomajor\\f31508\\fbidi \\froman\\fcharset238\\fprq2 Times New Roman CE;}\r\n{\\flomajor\\f31509\\fbidi \\froman\\fcharset204\\fprq2 Times New Roman Cyr;}{\\flomajor\\f31511\\fbidi \\froman\\fcharset161\\fprq2 Times New Roman Greek;}{\\flomajor\\f31512\\fbidi \\froman\\fcharset162\\fprq2 Times New Roman Tur;}\r\n{\\flomajor\\f31513\\fbidi \\froman\\fcharset177\\fprq2 Times New Roman (Hebrew);}{\\flomajor\\f31514\\fbidi \\froman\\fcharset178\\fprq2 Times New Roman (Arabic);}{\\flomajor\\f31515\\fbidi \\froman\\fcharset186\\fprq2 Times New Roman Baltic;}\r\n{\\flomajor\\f31516\\fbidi \\froman\\fcharset163\\fprq2 Times New Roman (Vietnamese);}{\\fdbmajor\\f31518\\fbidi \\froman\\fcharset238\\fprq2 Times New Roman CE;}{\\fdbmajor\\f31519\\fbidi \\froman\\fcharset204\\fprq2 Times New Roman Cyr;}\r\n{\\fdbmajor\\f31521\\fbidi \\froman\\fcharset161\\fprq2 Times New Roman Greek;}{\\fdbmajor\\f31522\\fbidi \\froman\\fcharset162\\fprq2 Times New Roman Tur;}{\\fdbmajor\\f31523\\fbidi \\froman\\fcharset177\\fprq2 Times New Roman (Hebrew);}\r\n{\\fdbmajor\\f31524\\fbidi \\froman\\fcharset178\\fprq2 Times New Roman (Arabic);}{\\fdbmajor\\f31525\\fbidi \\froman\\fcharset186\\fprq2 Times New Roman Baltic;}{\\fdbmajor\\f31526\\fbidi \\froman\\fcharset163\\fprq2 Times New Roman (Vietnamese);}\r\n{\\fhimajor\\f31528\\fbidi \\fswiss\\fcharset238\\fprq2 Calibri Light CE;}{\\fhimajor\\f31529\\fbidi \\fswiss\\fcharset204\\fprq2 Calibri Light Cyr;}{\\fhimajor\\f31531\\fbidi \\fswiss\\fcharset161\\fprq2 Calibri Light Greek;}\r\n{\\fhimajor\\f31532\\fbidi \\fswiss\\fcharset162\\fprq2 Calibri Light Tur;}{\\fhimajor\\f31533\\fbidi \\fswiss\\fcharset177\\fprq2 Calibri Light (Hebrew);}{\\fhimajor\\f31534\\fbidi \\fswiss\\fcharset178\\fprq2 Calibri Light (Arabic);}\r\n{\\fhimajor\\f31535\\fbidi \\fswiss\\fcharset186\\fprq2 Calibri Light Baltic;}{\\fhimajor\\f31536\\fbidi \\fswiss\\fcharset163\\fprq2 Calibri Light (Vietnamese);}{\\fbimajor\\f31538\\fbidi \\froman\\fcharset238\\fprq2 Times New Roman CE;}\r\n{\\fbimajor\\f31539\\fbidi \\froman\\fcharset204\\fprq2 Times New Roman Cyr;}{\\fbimajor\\f31541\\fbidi \\froman\\fcharset161\\fprq2 Times New Roman Greek;}{\\fbimajor\\f31542\\fbidi \\froman\\fcharset162\\fprq2 Times New Roman Tur;}\r\n{\\fbimajor\\f31543\\fbidi \\froman\\fcharset177\\fprq2 Times New Roman (Hebrew);}{\\fbimajor\\f31544\\fbidi \\froman\\fcharset178\\fprq2 Times New Roman (Arabic);}{\\fbimajor\\f31545\\fbidi \\froman\\fcharset186\\fprq2 Times New Roman Baltic;}\r\n{\\fbimajor\\f31546\\fbidi \\froman\\fcharset163\\fprq2 Times New Roman (Vietnamese);}{\\flominor\\f31548\\fbidi \\froman\\fcharset238\\fprq2 Times New Roman CE;}{\\flominor\\f31549\\fbidi \\froman\\fcharset204\\fprq2 Times New Roman Cyr;}\r\n{\\flominor\\f31551\\fbidi \\froman\\fcharset161\\fprq2 Times New Roman Greek;}{\\flominor\\f31552\\fbidi \\froman\\fcharset162\\fprq2 Times New Roman Tur;}{\\flominor\\f31553\\fbidi \\froman\\fcharset177\\fprq2 Times New Roman (Hebrew);}\r\n{\\flominor\\f31554\\fbidi \\froman\\fcharset178\\fprq2 Times New Roman (Arabic);}{\\flominor\\f31555\\fbidi \\froman\\fcharset186\\fprq2 Times New Roman Baltic;}{\\flominor\\f31556\\fbidi \\froman\\fcharset163\\fprq2 Times New Roman (Vietnamese);}\r\n{\\fdbminor\\f31558\\fbidi \\froman\\fcharset238\\fprq2 Times New Roman CE;}{\\fdbminor\\f31559\\fbidi \\froman\\fcharset204\\fprq2 Times New Roman Cyr;}{\\fdbminor\\f31561\\fbidi \\froman\\fcharset161\\fprq2 Times New Roman Greek;}\r\n{\\fdbminor\\f31562\\fbidi \\froman\\fcharset162\\fprq2 Times New Roman Tur;}{\\fdbminor\\f31563\\fbidi \\froman\\fcharset177\\fprq2 Times New Roman (Hebrew);}{\\fdbminor\\f31564\\fbidi \\froman\\fcharset178\\fprq2 Times New Roman (Arabic);}\r\n{\\fdbminor\\f31565\\fbidi \\froman\\fcharset186\\fprq2 Times New Roman Baltic;}{\\fdbminor\\f31566\\fbidi \\froman\\fcharset163\\fprq2 Times New Roman (Vietnamese);}{\\fhiminor\\f31568\\fbidi \\fswiss\\fcharset238\\fprq2 Calibri CE;}\r\n{\\fhiminor\\f31569\\fbidi \\fswiss\\fcharset204\\fprq2 Calibri Cyr;}{\\fhiminor\\f31571\\fbidi \\fswiss\\fcharset161\\fprq2 Calibri Greek;}{\\fhiminor\\f31572\\fbidi \\fswiss\\fcharset162\\fprq2 Calibri Tur;}\r\n{\\fhiminor\\f31573\\fbidi \\fswiss\\fcharset177\\fprq2 Calibri (Hebrew);}{\\fhiminor\\f31574\\fbidi \\fswiss\\fcharset178\\fprq2 Calibri (Arabic);}{\\fhiminor\\f31575\\fbidi \\fswiss\\fcharset186\\fprq2 Calibri Baltic;}\r\n{\\fhiminor\\f31576\\fbidi \\fswiss\\fcharset163\\fprq2 Calibri (Vietnamese);}{\\fbiminor\\f31578\\fbidi \\froman\\fcharset238\\fprq2 Times New Roman CE;}{\\fbiminor\\f31579\\fbidi \\froman\\fcharset204\\fprq2 Times New Roman Cyr;}\r\n{\\fbiminor\\f31581\\fbidi \\froman\\fcharset161\\fprq2 Times New Roman Greek;}{\\fbiminor\\f31582\\fbidi \\froman\\fcharset162\\fprq2 Times New Roman Tur;}{\\fbiminor\\f31583\\fbidi \\froman\\fcharset177\\fprq2 Times New Roman (Hebrew);}\r\n{\\fbiminor\\f31584\\fbidi \\froman\\fcharset178\\fprq2 Times New Roman (Arabic);}{\\fbiminor\\f31585\\fbidi \\froman\\fcharset186\\fprq2 Times New Roman Baltic;}{\\fbiminor\\f31586\\fbidi \\froman\\fcharset163\\fprq2 Times New Roman (Vietnamese);}}\r\n{\\colortbl;\\red0\\green0\\blue0;\\red0\\green0\\blue255;\\red0\\green255\\blue255;\\red0\\green255\\blue0;\\red255\\green0\\blue255;\\red255\\green0\\blue0;\\red255\\green255\\blue0;\\red255\\green255\\blue255;\\red0\\green0\\blue128;\\red0\\green128\\blue128;\\red0\\green128\\blue0;\r\n\\red128\\green0\\blue128;\\red128\\green0\\blue0;\\red128\\green128\\blue0;\\red128\\green128\\blue128;\\red192\\green192\\blue192;\\red0\\green0\\blue0;\\red0\\green0\\blue0;\\red74\\green92\\blue140;}{\\*\\defchp }{\\*\\defpap \r\n\\ql \\li0\\ri0\\widctlpar\\wrapdefault\\aspalpha\\aspnum\\faauto\\adjustright\\rin0\\lin0\\itap0 }\\noqfpromote {\\stylesheet{\\ql \\li0\\ri0\\widctlpar\\wrapdefault\\aspalpha\\aspnum\\faauto\\adjustright\\rin0\\lin0\\itap0 \\rtlch\\fcs1 \\af0\\afs24\\alang1025 \\ltrch\\fcs0 \r\n\\fs24\\lang1033\\langfe1033\\cgrid\\langnp1033\\langfenp1033 \\snext0 \\sqformat \\spriority0 Normal;}{\\s1\\ql \\li0\\ri0\\sb240\\sa60\\keepn\\widctlpar\\wrapdefault\\aspalpha\\aspnum\\faauto\\outlinelevel0\\adjustright\\rin0\\lin0\\itap0 \\rtlch\\fcs1 \\ab\\af1\\afs32\\alang1025 \r\n\\ltrch\\fcs0 \\b\\fs32\\lang1033\\langfe1041\\kerning32\\loch\\f1\\hich\\af1\\dbch\\af11\\cgrid\\langnp1033\\langfenp1041 \\sbasedon0 \\snext1 \\slink24 \\sqformat \\spriority9 heading 1;}{\\*\\cs10 \\additive \\ssemihidden \\sunhideused \\spriority1 Default Paragraph Font;}{\\*\r\n\\ts11\\tsrowd\\trftsWidthB3\\trpaddl108\\trpaddr108\\trpaddfl3\\trpaddft3\\trpaddfb3\\trpaddfr3\\tblind0\\tblindtype3\\tsvertalt\\tsbrdrt\\tsbrdrl\\tsbrdrb\\tsbrdrr\\tsbrdrdgl\\tsbrdrdgr\\tsbrdrh\\tsbrdrv \r\n\\ql \\li0\\ri0\\widctlpar\\wrapdefault\\aspalpha\\aspnum\\faauto\\adjustright\\rin0\\lin0\\itap0 \\rtlch\\fcs1 \\af0\\afs20\\alang1025 \\ltrch\\fcs0 \\fs20\\lang1033\\langfe1033\\cgrid\\langnp1033\\langfenp1033 \\snext11 \\ssemihidden \\sunhideused Normal Table;}{\\*\r\n\\ts15\\tsrowd\\trftsWidthB3\\trpaddl108\\trpaddr108\\trpaddfl3\\trpaddft3\\trpaddfb3\\trpaddfr3\\tblind0\\tblindtype3\\tsvertalt\\tsbrdrt\\tsbrdrl\\tsbrdrb\\tsbrdrr\\tsbrdrdgl\\tsbrdrdgr\\tsbrdrh\\tsbrdrv \r\n\\ql \\li0\\ri0\\widctlpar\\wrapdefault\\aspalpha\\aspnum\\faauto\\adjustright\\rin0\\lin0\\itap0 \\rtlch\\fcs1 \\af0\\afs20\\alang1025 \\ltrch\\fcs0 \\fs20\\lang1033\\langfe1033\\cgrid\\langnp1033\\langfenp1033 \\sbasedon11 \\snext15 \\spriority0 Table Grid;}{\r\n\\s16\\ql \\li0\\ri0\\widctlpar\\wrapdefault\\aspalpha\\aspnum\\faauto\\adjustright\\rin0\\lin0\\itap0 \\rtlch\\fcs1 \\af0\\afs32\\alang1025 \\ltrch\\fcs0 \\b\\i\\f1\\fs32\\lang1033\\langfe1033\\super\\cgrid\\langnp1033\\langfenp1033 \\sbasedon0 \\snext16 \\spriority0 Hello;}{\r\n\\s17\\ql \\li1440\\ri1440\\sa120\\widctlpar\\wrapdefault\\aspalpha\\aspnum\\faauto\\adjustright\\rin1440\\lin1440\\itap0 \\rtlch\\fcs1 \\af0\\afs24\\alang1025 \\ltrch\\fcs0 \\fs24\\lang1033\\langfe1033\\cgrid\\langnp1033\\langfenp1033 \\sbasedon0 \\snext17 \\spriority0 Block Text;}{\r\n\\s18\\ql \\li0\\ri0\\sb100\\sa100\\sbauto1\\saauto1\\widctlpar\\wrapdefault\\aspalpha\\aspnum\\faauto\\adjustright\\rin0\\lin0\\itap0 \\rtlch\\fcs1 \\af0\\afs24\\alang1025 \\ltrch\\fcs0 \\fs24\\lang1033\\langfe1033\\cgrid\\langnp1033\\langfenp1033 \\sbasedon0 \\snext18 \\spriority0 \r\nNormal (Web);}{\\*\\cs19 \\additive \\ul\\cf2 \\spriority0 Hyperlink;}{\\s20\\ql \\li0\\ri0\\widctlpar\\wrapdefault\\faauto\\rin0\\lin0\\itap0 \\rtlch\\fcs1 \\af0\\afs24\\alang1025 \\ltrch\\fcs0 \\f40\\fs24\\lang1024\\langfe1024\\cgrid\\noproof\\langnp1033\\langfenp1033 \r\n\\snext20 \\spriority0 4;}{\\s21\\ql \\li180\\ri0\\widctlpar\\wrapdefault\\faauto\\rin0\\lin180\\itap0 \\rtlch\\fcs1 \\af0\\afs24\\alang1025 \\ltrch\\fcs0 \\f40\\fs24\\lang1024\\langfe1024\\cgrid\\noproof\\langnp1033\\langfenp1033 \\snext21 \\spriority0 24;}{\\*\\cs22 \\additive \r\n\\fs16\\cf1 \\spriority0 18;}{\\*\\cs23 \\additive \\b\\fs18\\cf19 \\spriority0 23;}{\\*\\cs24 \\additive \\b\\fs32\\lang0\\langfe1041\\kerning32\\loch\\f1\\hich\\af1\\dbch\\af11\\langfenp1041 \\slink1 \\spriority0 Heading 1 Char;}{\\*\\cs25 \\additive \\fs16\\cf1 \\spriority0 10;}{\r\n\\s26\\ql \\li0\\ri0\\widctlpar\\tqc\\tx4513\\tqr\\tx9026\\wrapdefault\\aspalpha\\aspnum\\faauto\\adjustright\\rin0\\lin0\\itap0 \\rtlch\\fcs1 \\af0\\afs24\\alang1025 \\ltrch\\fcs0 \\fs24\\lang1033\\langfe1033\\cgrid\\langnp1033\\langfenp1033 \\sbasedon0 \\snext26 \\slink27 \\spriority0 \r\nheader;}{\\*\\cs27 \\additive \\fs24\\lang1033\\langfe1033\\animtext0\\langnp1033\\langfenp1033 \\slink26 \\spriority0 Header Char;}{\\s28\\ql \\li0\\ri0\\widctlpar\\tqc\\tx4513\\tqr\\tx9026\\wrapdefault\\aspalpha\\aspnum\\faauto\\adjustright\\rin0\\lin0\\itap0 \\rtlch\\fcs1 \r\n\\af0\\afs24\\alang1025 \\ltrch\\fcs0 \\fs24\\lang1033\\langfe1033\\cgrid\\langnp1033\\langfenp1033 \\sbasedon0 \\snext28 \\slink29 \\spriority0 footer;}{\\*\\cs29 \\additive \\fs24\\lang1033\\langfe1033\\animtext0\\langnp1033\\langfenp1033 \\slink28 \\spriority0 Footer Char;}}\r\n{\\*\\listtable{\\list\\listtemplateid193356080{\\listlevel\\levelnfc23\\levelnfcn23\\leveljc0\\leveljcn0\\levelfollow0\\levelstartat1\\levelspace0\\levelindent0{\\leveltext\\'01\\u-3913 ?;}{\\levelnumbers;}\\loch\\af3\\hich\\af3\\dbch\\af3 \\li720\\lin720 }{\\listlevel\\levelnfc23\r\n\\levelnfcn23\\leveljc0\\leveljcn0\\levelfollow0\\levelstartat1\\levelspace0\\levelindent0{\\leveltext\\'01o;}{\\levelnumbers;}\\loch\\af2\\hich\\af2\\dbch\\af2 \\li1440\\lin1440 }{\\listlevel\\levelnfc23\\levelnfcn23\\leveljc0\\leveljcn0\\levelfollow0\\levelstartat1\\levelspace0\r\n\\levelindent0{\\leveltext\\'01\\u-3929 ?;}{\\levelnumbers;}\\loch\\af10\\hich\\af10\\dbch\\af10 \\li2160\\lin2160 }{\\listlevel\\levelnfc23\\levelnfcn23\\leveljc0\\leveljcn0\\levelfollow0\\levelstartat1\\levelspace0\\levelindent0{\\leveltext\\'01\\u-3913 ?;}{\\levelnumbers;}\r\n\\loch\\af3\\hich\\af3\\dbch\\af3 \\li2880\\lin2880 }{\\listlevel\\levelnfc23\\levelnfcn23\\leveljc0\\leveljcn0\\levelfollow0\\levelstartat1\\levelspace0\\levelindent0{\\leveltext\\'01o;}{\\levelnumbers;}\\loch\\af2\\hich\\af2\\dbch\\af2 \\li3600\\lin3600 }{\\listlevel\\levelnfc23\r\n\\levelnfcn23\\leveljc0\\leveljcn0\\levelfollow0\\levelstartat1\\levelspace0\\levelindent0{\\leveltext\\'01\\u-3929 ?;}{\\levelnumbers;}\\loch\\af10\\hich\\af10\\dbch\\af10 \\li4320\\lin4320 }{\\listlevel\\levelnfc23\\levelnfcn23\\leveljc0\\leveljcn0\\levelfollow0\\levelstartat1\r\n\\levelspace0\\levelindent0{\\leveltext\\'01\\u-3913 ?;}{\\levelnumbers;}\\loch\\af3\\hich\\af3\\dbch\\af3 \\li5040\\lin5040 }{\\listlevel\\levelnfc23\\levelnfcn23\\leveljc0\\leveljcn0\\levelfollow0\\levelstartat1\\levelspace0\\levelindent0{\\leveltext\\'01o;}{\\levelnumbers;}\r\n\\loch\\af2\\hich\\af2\\dbch\\af2 \\li5760\\lin5760 }{\\listlevel\\levelnfc23\\levelnfcn23\\leveljc0\\leveljcn0\\levelfollow0\\levelstartat1\\levelspace0\\levelindent0{\\leveltext\\'01\\u-3929 ?;}{\\levelnumbers;}\\loch\\af10\\hich\\af10\\dbch\\af10 \\li6480\\lin6480 }{\\listname \r\n;}\\listid1}{\\list\\listtemplateid-446525618{\\listlevel\\levelnfc0\\levelnfcn0\\leveljc0\\leveljcn0\\levelfollow0\\levelstartat1\\levelspace0\\levelindent0{\\leveltext\\'02\\'00.;}{\\levelnumbers\\'01;}\\rtlch\\fcs1 \\af0 \\ltrch\\fcs0 \\fi-360\\li720\\lin720 }{\\listlevel\r\n\\levelnfc4\\levelnfcn4\\leveljc0\\leveljcn0\\levelfollow0\\levelstartat1\\levelspace0\\levelindent0{\\leveltext\\'02\\'01.;}{\\levelnumbers\\'01;}\\rtlch\\fcs1 \\af0 \\ltrch\\fcs0 \\fi-360\\li1440\\lin1440 }{\\listlevel\\levelnfc2\\levelnfcn2\\leveljc2\\leveljcn2\\levelfollow0\r\n\\levelstartat1\\levelspace0\\levelindent0{\\leveltext\\'02\\'02.;}{\\levelnumbers\\'01;}\\rtlch\\fcs1 \\af0 \\ltrch\\fcs0 \\fi-180\\li2160\\lin2160 }{\\listlevel\\levelnfc0\\levelnfcn0\\leveljc0\\leveljcn0\\levelfollow0\\levelstartat1\\levelspace0\\levelindent0{\\leveltext\r\n\\'02\\'03.;}{\\levelnumbers\\'01;}\\rtlch\\fcs1 \\af0 \\ltrch\\fcs0 \\fi-360\\li2880\\lin2880 }{\\listlevel\\levelnfc4\\levelnfcn4\\leveljc0\\leveljcn0\\levelfollow0\\levelstartat1\\levelspace0\\levelindent0{\\leveltext\\'02\\'04.;}{\\levelnumbers\\'01;}\\rtlch\\fcs1 \\af0 \r\n\\ltrch\\fcs0 \\fi-360\\li3600\\lin3600 }{\\listlevel\\levelnfc2\\levelnfcn2\\leveljc2\\leveljcn2\\levelfollow0\\levelstartat1\\levelspace0\\levelindent0{\\leveltext\\'02\\'05.;}{\\levelnumbers\\'01;}\\rtlch\\fcs1 \\af0 \\ltrch\\fcs0 \\fi-180\\li4320\\lin4320 }{\\listlevel\\levelnfc0\r\n\\levelnfcn0\\leveljc0\\leveljcn0\\levelfollow0\\levelstartat1\\levelspace0\\levelindent0{\\leveltext\\'02\\'06.;}{\\levelnumbers\\'01;}\\rtlch\\fcs1 \\af0 \\ltrch\\fcs0 \\fi-360\\li5040\\lin5040 }{\\listlevel\\levelnfc4\\levelnfcn4\\leveljc0\\leveljcn0\\levelfollow0\\levelstartat1\r\n\\levelspace0\\levelindent0{\\leveltext\\'02\\'07.;}{\\levelnumbers\\'01;}\\rtlch\\fcs1 \\af0 \\ltrch\\fcs0 \\fi-360\\li5760\\lin5760 }{\\listlevel\\levelnfc2\\levelnfcn2\\leveljc2\\leveljcn2\\levelfollow0\\levelstartat1\\levelspace0\\levelindent0{\\leveltext\r\n\\'02\\'08.;}{\\levelnumbers\\'01;}\\rtlch\\fcs1 \\af0 \\ltrch\\fcs0 \\fi-180\\li6480\\lin6480 }{\\listname ;}\\listid10}{\\list\\listtemplateid1073928198{\\listlevel\\levelnfc0\\levelnfcn0\\leveljc0\\leveljcn0\\levelfollow0\\levelstartat1\\levelspace0\\levelindent0{\\leveltext\r\n\\'02\\'00.;}{\\levelnumbers\\'01;}\\rtlch\\fcs1 \\af0 \\ltrch\\fcs0 \\li720\\lin720 }{\\listlevel\\levelnfc4\\levelnfcn4\\leveljc2\\leveljcn2\\levelfollow0\\levelstartat1\\levelspace0\\levelindent0{\\leveltext\\'02\\'01.;}{\\levelnumbers\\'01;}\\rtlch\\fcs1 \\af0 \\ltrch\\fcs0 \r\n\\li1440\\lin1440 }{\\listlevel\\levelnfc2\\levelnfcn2\\leveljc0\\leveljcn0\\levelfollow0\\levelstartat1\\levelspace0\\levelindent0{\\leveltext\\'02\\'02.;}{\\levelnumbers\\'01;}\\rtlch\\fcs1 \\af0 \\ltrch\\fcs0 \\li2160\\lin2160 }{\\listlevel\\levelnfc0\\levelnfcn0\\leveljc0\r\n\\leveljcn0\\levelfollow0\\levelstartat1\\levelspace0\\levelindent0{\\leveltext\\'02\\'03.;}{\\levelnumbers\\'01;}\\rtlch\\fcs1 \\af0 \\ltrch\\fcs0 \\li2880\\lin2880 }{\\listlevel\\levelnfc4\\levelnfcn4\\leveljc2\\leveljcn2\\levelfollow0\\levelstartat1\\levelspace0\\levelindent0\r\n{\\leveltext\\'02\\'04.;}{\\levelnumbers\\'01;}\\rtlch\\fcs1 \\af0 \\ltrch\\fcs0 \\li3600\\lin3600 }{\\listlevel\\levelnfc2\\levelnfcn2\\leveljc0\\leveljcn0\\levelfollow0\\levelstartat1\\levelspace0\\levelindent0{\\leveltext\\'02\\'05.;}{\\levelnumbers\\'01;}\\rtlch\\fcs1 \\af0 \r\n\\ltrch\\fcs0 \\li4320\\lin4320 }{\\listlevel\\levelnfc0\\levelnfcn0\\leveljc0\\leveljcn0\\levelfollow0\\levelstartat1\\levelspace0\\levelindent0{\\leveltext\\'02\\'06.;}{\\levelnumbers\\'01;}\\rtlch\\fcs1 \\af0 \\ltrch\\fcs0 \\li5040\\lin5040 }{\\listlevel\\levelnfc4\\levelnfcn4\r\n\\leveljc2\\leveljcn2\\levelfollow0\\levelstartat1\\levelspace0\\levelindent0{\\leveltext\\'02\\'07.;}{\\levelnumbers\\'01;}\\rtlch\\fcs1 \\af0 \\ltrch\\fcs0 \\li5760\\lin5760 }{\\listlevel\\levelnfc2\\levelnfcn2\\leveljc0\\leveljcn0\\levelfollow0\\levelstartat1\\levelspace0\r\n\\levelindent0{\\leveltext\\'02\\'08.;}{\\levelnumbers\\'01;}\\rtlch\\fcs1 \\af0 \\ltrch\\fcs0 \\li6480\\lin6480 }{\\listname ;}\\listid134032691}}{\\*\\listoverridetable{\\listoverride\\listid134032691\\listoverridecount0\\ls1}{\\listoverride\\listid1\\listoverridecount0\\ls2}\r\n{\\listoverride\\listid10\\listoverridecount0\\ls3}}{\\*\\rsidtbl \\rsid3215039\\rsid7044654\\rsid8002005\\rsid9847396\\rsid9973197\\rsid11094202\\rsid13521093\\rsid14422550\\rsid14818952}{\\mmathPr\\mmathFont34\\mbrkBin0\\mbrkBinSub0\\msmallFrac0\\mdispDef1\\mlMargin0\r\n\\mrMargin0\\mdefJc1\\mwrapIndent1440\\mintLim0\\mnaryLim1}{\\info{\\title Essential DocIO}{\\author syncfusion}{\\operator Suriya Balamurugan}{\\creatim\\yr2024\\mo6\\dy13\\hr23\\min45}{\\revtim\\yr2024\\mo6\\dy13\\hr23\\min45}{\\version2}{\\edmins0}{\\nofpages1}{\\nofwords66}\r\n{\\nofchars381}{\\nofcharsws446}{\\vern79}}{\\*\\xmlnstbl {\\xmlns1 http://schemas.microsoft.com/office/word/2003/wordml}}\\paperw11200\\paperh15840\\margl1440\\margr1440\\margt1440\\margb1440\\gutter0\\ltrsect \r\n\\widowctrl\\ftnbj\\aenddoc\\trackmoves0\\trackformatting1\\donotembedsysfont1\\relyonvml0\\donotembedlingdata0\\grfdocevents0\\validatexml1\\showplaceholdtext0\\ignoremixedcontent0\\saveinvalidxml0\\showxmlerrors1\\noxlattoyen\r\n\\expshrtn\\noultrlspc\\dntblnsbdb\\nospaceforul\\formshade\\horzdoc\\dgmargin\\dghspace180\\dgvspace180\\dghorigin1440\\dgvorigin1440\\dghshow1\\dgvshow1\r\n\\jexpand\\viewkind1\\viewscale100\\pgbrdrhead\\pgbrdrfoot\\splytwnine\\ftnlytwnine\\htmautsp\\nolnhtadjtbl\\useltbaln\\alntblind\\lytcalctblwd\\lyttblrtgr\\lnbrkrule\\nobrkwrptbl\\snaptogridincell\\allowfieldendsel\\wrppunct\r\n\\asianbrkrule\\rsidroot3215039\\newtblstyruls\\nogrowautofit\\usenormstyforlist\\noindnmbrts\\felnbrelev\\nocxsptable\\indrlsweleven\\noafcnsttbl\\afelev\\utinl\\hwelev\\spltpgpar\\notcvasp\\notbrkcnstfrctbl\\notvatxbx\\krnprsnet\\cachedcolbal \\nouicompat \\fet0\r\n{\\*\\wgrffmtfilter 2450}\\nofeaturethrottle1\\ilfomacatclnup0{\\*\\ftnsep \\ltrpar \\pard\\plain \\ltrpar\\ql \\li0\\ri0\\widctlpar\\wrapdefault\\aspalpha\\aspnum\\faauto\\adjustright\\rin0\\lin0\\itap0 \\rtlch\\fcs1 \\af0\\afs24\\alang1025 \\ltrch\\fcs0 \r\n\\fs24\\lang1033\\langfe1033\\cgrid\\langnp1033\\langfenp1033 {\\rtlch\\fcs1 \\af0 \\ltrch\\fcs0 \\insrsid11094202 \\chftnsep \r\n\\par }}{\\*\\ftnsepc \\ltrpar \\pard\\plain \\ltrpar\\ql \\li0\\ri0\\widctlpar\\wrapdefault\\aspalpha\\aspnum\\faauto\\adjustright\\rin0\\lin0\\itap0 \\rtlch\\fcs1 \\af0\\afs24\\alang1025 \\ltrch\\fcs0 \\fs24\\lang1033\\langfe1033\\cgrid\\langnp1033\\langfenp1033 {\\rtlch\\fcs1 \\af0 \r\n\\ltrch\\fcs0 \\insrsid11094202 \\chftnsepc \r\n\\par }}{\\*\\aftnsep \\ltrpar \\pard\\plain \\ltrpar\\ql \\li0\\ri0\\widctlpar\\wrapdefault\\aspalpha\\aspnum\\faauto\\adjustright\\rin0\\lin0\\itap0 \\rtlch\\fcs1 \\af0\\afs24\\alang1025 \\ltrch\\fcs0 \\fs24\\lang1033\\langfe1033\\cgrid\\langnp1033\\langfenp1033 {\\rtlch\\fcs1 \\af0 \r\n\\ltrch\\fcs0 \\insrsid11094202 \\chftnsep \r\n\\par }}{\\*\\aftnsepc \\ltrpar \\pard\\plain \\ltrpar\\ql \\li0\\ri0\\widctlpar\\wrapdefault\\aspalpha\\aspnum\\faauto\\adjustright\\rin0\\lin0\\itap0 \\rtlch\\fcs1 \\af0\\afs24\\alang1025 \\ltrch\\fcs0 \\fs24\\lang1033\\langfe1033\\cgrid\\langnp1033\\langfenp1033 {\\rtlch\\fcs1 \\af0 \r\n\\ltrch\\fcs0 \\insrsid11094202 \\chftnsepc \r\n\\par }}\\ltrpar \\sectd \\ltrsect\\sbknone\\linex0\\endnhere\\sectdefaultcl\\sftnbj {\\*\\pnseclvl1\\pnucrm\\pnstart1\\pnindent720\\pnhang {\\pntxta .}}{\\*\\pnseclvl2\\pnucltr\\pnstart1\\pnindent720\\pnhang {\\pntxta .}}{\\*\\pnseclvl3\\pndec\\pnstart1\\pnindent720\\pnhang {\\pntxta .}}\r\n{\\*\\pnseclvl4\\pnlcltr\\pnstart1\\pnindent720\\pnhang {\\pntxta )}}{\\*\\pnseclvl5\\pndec\\pnstart1\\pnindent720\\pnhang {\\pntxtb (}{\\pntxta )}}{\\*\\pnseclvl6\\pnlcltr\\pnstart1\\pnindent720\\pnhang {\\pntxtb (}{\\pntxta )}}{\\*\\pnseclvl7\\pnlcrm\\pnstart1\\pnindent720\\pnhang \r\n{\\pntxtb (}{\\pntxta )}}{\\*\\pnseclvl8\\pnlcltr\\pnstart1\\pnindent720\\pnhang {\\pntxtb (}{\\pntxta )}}{\\*\\pnseclvl9\\pnlcrm\\pnstart1\\pnindent720\\pnhang {\\pntxtb (}{\\pntxta )}}\\pard\\plain \\ltrpar\r\n\\s1\\qc \\li0\\ri0\\sb240\\sa60\\keepn\\widctlpar\\wrapdefault\\aspalpha\\aspnum\\faauto\\outlinelevel0\\adjustright\\rin0\\lin0\\itap0 \\rtlch\\fcs1 \\ab\\af1\\afs32\\alang1025 \\ltrch\\fcs0 \r\n\\b\\fs32\\lang1033\\langfe1041\\kerning32\\loch\\af1\\hich\\af1\\dbch\\af11\\cgrid\\langnp1033\\langfenp1041 {\\rtlch\\fcs1 \\af37 \\ltrch\\fcs0 \\fs36\\loch\\af37\\hich\\af37\\dbch\\af37\\insrsid8002005 \\hich\\af37\\dbch\\af37\\loch\\f37 Adventure Works Cycles}{\\rtlch\\fcs1 \\af1 \r\n\\ltrch\\fcs0 \\insrsid3215039 \r\n\\par }\\pard\\plain \\ltrpar\\qj \\fi720\\li0\\ri0\\widctlpar\\wrapdefault\\aspalpha\\aspnum\\faauto\\adjustright\\rin0\\lin0\\itap0 \\rtlch\\fcs1 \\af0\\afs24\\alang1025 \\ltrch\\fcs0 \\fs24\\lang1033\\langfe1033\\cgrid\\langnp1033\\langfenp1033 {\\rtlch\\fcs1 \\af0 \\ltrch\\fcs0 \r\n\\insrsid8002005 Adventure Works Cycles, the fictitious company on which the AdventureWorks sample databases are based, is a large, }{\\rtlch\\fcs1 \\af0 \\ltrch\\fcs0 \\ul\\insrsid8002005\\charrsid9973197 multinational}{\\rtlch\\fcs1 \\af0 \\ltrch\\fcs0 \r\n\\insrsid8002005 manufacturing company. The company manufactures and sells metal and composite bicycles to North American, European and Asian commercial markets. While its base operation is located in Bothell, Washington with 290 }{\\rtlch\\fcs1 \\ab\\ai\\af0 \r\n\\ltrch\\fcs0 \\b\\i\\insrsid8002005\\charrsid9973197 employees}{\\rtlch\\fcs1 \\af0 \\ltrch\\fcs0 \\insrsid8002005 , several regional sales teams are located throughout their market base.}{\\rtlch\\fcs1 \\af0 \\ltrch\\fcs0 \\insrsid3215039 \r\n\\par }}";
// Convert RTF string to memory stream.
byte[] bytes = Encoding.ASCII.GetBytes(RtfString);
using (MemoryStream memoryStream = new MemoryStream(bytes))
{
// Open an existing RTF document from stream.
using (WordDocument RTFDocument = new WordDocument(memoryStream, FormatType.Rtf))
{
using (FileStream fileStreamPath = new FileStream(Path.GetFullPath(@"Data/Template.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
// Open an existing Word document.
using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Docx))
{
#region Find one text and apply character format
// Finds first occurrence of the text in the RTF document.
TextSelection textSelection = RTFDocument.Find("Adventure Works Cycles", false, false);
// Get the character format of the text in the RTF document.
WCharacterFormat rtfTextCharacterFormat = textSelection.GetAsOneRange().CharacterFormat;
// Finds first occurrence of the text in the Word document.
textSelection = document.Find("Adventure Works Cycles", false, false);
// Apply character format of the text in the RTF document to the text in the Word document.
textSelection.GetAsOneRange().ApplyCharacterFormat(rtfTextCharacterFormat);
#endregion
#region Find another one text and apply particular character format alone
// Finds first occurrence of the text in the RTF document.
textSelection = RTFDocument.Find("multinational", false, false);
// Get the character format of the text in the RTF document.
rtfTextCharacterFormat = textSelection.GetAsOneRange().CharacterFormat;
// Finds first occurrence of the text in the Word document.
textSelection = document.Find("multinational", false, false);
// Apply particular format alone of the text in the RTF document to the text in the Word document.
textSelection.GetAsOneRange().CharacterFormat.UnderlineStyle = rtfTextCharacterFormat.UnderlineStyle;
#endregion
#region Find another one text and apply character format
// Finds first occurrence of the text in the RTF document.
textSelection = RTFDocument.Find("employees", false, false);
// Get the character format of the text in the RTF document.
rtfTextCharacterFormat = textSelection.GetAsOneRange().CharacterFormat;
// Finds first occurrence of the text in the Word document.
textSelection = document.Find("employees", false, false);
// Apply character format of the text in the RTF document to the text in the Word document.
textSelection.GetAsOneRange().ApplyCharacterFormat(rtfTextCharacterFormat);
#endregion
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.ReadWrite))
{
// Saves the Word document.
document.Save(outputFileStream, FormatType.Docx);
}
}
}
}
}
You can download a complete working sample to copy the format of the text from an RTF string and apply it to text in DOCX format document from the GitHub.
By executing the program, you will get the Word document as follows.
Take a moment to peruse the documentation where you can find basic Word document processing options along with the features like mail merge, merge, split, and compare Word documents, find and replace text in the Word document, protect the Word documents, and most importantly, the PDF and Image conversions with code examples.
Conclusion
I hope you enjoyed learning about how to copy the format of the text from an RTF string and apply it to text in DOCX format document.
You can refer to our ASP.NET Core DocIO feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our ASP.NET Core DocIO example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!