We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

RTF String parse before replacement the tag

Need to parse rtf format document string before replacement with actual tag
i am using the below code

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
ParagraphFormat paragraphFormat = builder.ParagraphFormat;
mystr = "{\rtf1\ansi{\fonttbl\f0\fswiss Helvetica;}\f0\pardThis is some {\b bold} text.\par}";
builder.Writeln(myStr);

Please help to parse the mystr string to the document

Hi Pankaj,

Thanks
for your inquiry. Please use the following code example to achieve your
requirements. Please check the detail of InsertDocument from here:
https://docs.aspose.com/words/java/insert-and-append-documents/

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
ParagraphFormat paragraphFormat = builder.ParagraphFormat;
String mystr = @"{.....\par}";
Document rtf = RtfStringToDocument(mystr);
InsertDocument(doc.LastSection.Body.LastParagraph, rtf);
doc.Save(MyDir + "Out.docx");
private static Document RtfStringToDocument(string rtf)
{
    Document doc = null;
    // Convert RTF string to byte array.
    byte[] rtfBytes = Encoding.UTF8.GetBytes(rtf);
    // Create stream.
    using (MemoryStream rtfStream = new MemoryStream(rtfBytes))
    {
        // Open document from stream.
        doc = new Document(rtfStream);
    }
    return doc;
}