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\pard
This is some {\b bold} text.\par
}
builder.Writeln(myStr);
Please help to parse the mystr string to the document
Hi Pankaj,
for your inquiry. Please use the following code example to achieve your
requirements. Please check the detail of InsertDocument from here:
http://www.aspose.com/docs/display/wordsnet/How+to++Insert+a+Document+into+another+Document
<!–[if gte mso 9]>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:DoNotShowPropertyChanges/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>X-NONE</w:LidThemeAsian>
<w:LidThemeComplexScript>AR-SA</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:EnableOpenTypeKerning/>
<w:DontFlipMirrorIndents/>
<w:OverrideTableStyleHps/>
</w:Compatibility>
<m:mathPr>
<m:mathFont m:val=“Cambria Math”/>
<m:brkBin m:val=“before”/>
<m:brkBinSub m:val="–"/>
<m:smallFrac m:val=“off”/>
<m:dispDef/>
<m:lMargin m:val=“0”/>
<m:rMargin m:val=“0”/>
<m:defJc m:val=“centerGroup”/>
<m:wrapIndent m:val=“1440”/>
<m:intLim m:val=“subSup”/>
<m:naryLim m:val=“undOvr”/>
</m:mathPr></w:WordDocument>
<![endif]–><!–[if gte mso 10]>
<![endif]–>
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;
}