String in RTF format in docx JAVA

Hello,
I recieve as parameter a String in RTF wihch is conntening this : “{\rtf1\fbidis\ansi\ansicpg1252\deff0\deflang1036{\fonttbl{\f0\fswiss\fprq2\fcharset0 Arial;}{\f1\froman\fprq2\fcharset2 Symbol;}{\f2\fnil\fcharset0 MS Shell Dlg;}}
\viewkind4\uc1\pard\ltrpar\fi-357\li714\sb360\tx5580\tx8100\b\f0\fs20 I.\tab\ul Objectif de la proc’e9dure\par…”

I need to insert this String into a docx document but when i use builder.write(myRTFstring); it’s just write the rft code. How can I insert this string into my document.docx and keep the text’s layout ?

thanks
Ana

@anamnisy

In your case, we suggest you following solution.

  1. Convert the string RTF into InputStream.
  2. Load the document from input stream into Aspose.Words’ DOM.
  3. Move the cursor to the desired location in destination document where you want to insert RTF.
  4. Please use DocumentBuilder.InsertDocument method to insert the RTF document loaded at step 2.

Please read the following articles and check the code snippet. Hope this helps you.
Open from a Stream
Moving the Cursor

String initialString = "{\\rtf1\\fbidis\\ansi\\ansicpg1252\\deff0\\deflang1036{\\fonttbl{\\f0\\fswiss\\fprq2\\fcharset0 Arial;}{\\f1\\froman\\fprq2\\fcharset2 Symbol;}{\\f2\\fnil\\fcharset0 MS Shell Dlg;}}\n" +
        "\\viewkind4\\uc1\\pard\\ltrpar\\fi-357\\li714\\sb360\\tx5580\\tx8100\\b\\f0\\fs20 I.\\tab\\ul Objectif de la proc’e9dure\\par..}";
InputStream in = new ByteArrayInputStream(initialString.getBytes());

Document doc = new Document(in);

Hi, thanks for your answer!
I have another issue with that : i’m saving the rtdf doc in rtdDoc.docx after using stream.
And i’m using the static insertDocument() function provided by aspose documentation in order to insert that document in my main document after one title.
The probleme is that insertDocument() is creating another node after my tilte’s one and is leaving a break page.
How can i remove it?
P1.zip (1.4 KB)

@anamnisy

Please use DocumentBuilder.InsertDocument method to insert a document instead of the method that you are using in your code. Hope this helps you.