Welcome to OpenXML Developer Sign in | Join | Help

RTF to WordprocessingML

Last post 10-07-2008, 4:48 AM by beast. 3 replies.
Sort Posts: Previous Next
  •  08-04-2008, 5:11 PM 3530

    RTF to WordprocessingML

    In my RTF Control the following String exists e.g.

    \rtf1\ansi\ansicpg1252\deff0\deflang1031{\fonttbl{\f0\fnil\fcharset0 Arial;}}" & _

    \viewkind4\uc1\pard\fs20 neuer test1\par\fs28 neuer test2\par\fs32 neuer test3\fs20\par" & }


    Is there a possibility to tramsform or parse such expressions into WordprocessingML (Nodes and attributes etc..), because saving it and opening it with MS Word is no suitable solution.

    Does anybody knoe such a parser or how to find a transformer for such a general problem ?

    Or how do others transform user data including data and formating together instead of RTF controls ?

    Thanks for every hint,

    best regards....

  •  08-06-2008, 12:30 AM 3535 in reply to 3530

    Re: RTF to WordprocessingML

    You can convert the rtf to xml using rtf2xml [1] or majix [2], and then transform it to WordML (pkg format at least). 

    Or you could use try the rtf parser in the JDK. 

    If you are using java, you could use docx4j to create the WordML package.

    cheers .. Jason

    [1] http://sourceforge.net/projects/rtf2xml/
    [2] http://sourceforge.net/projects/majix/

    There is also http://webcat.sourceforge.net/javadocs/pt/tumba/parser/rtf/RTF2HTML.html
  •  08-26-2008, 11:04 AM 3610 in reply to 3535

    Re: RTF to WordprocessingML

    I'm using vb.net

     

    is there also an rtf parser for dotnet like the JDK etc.. ?

     

    thanks

  •  10-07-2008, 4:48 AM 3762 in reply to 3610

    Re: RTF to WordprocessingML

    Hi

     

    You can easy convert RTF to WML using Aspose.Words. Here is code:

     

    //Open RTF doc

    Document doc = new Document("in.rtf");

    //save in WML

    doc.Save("out.xml", SaveFormat.WordML);

     

    Also here is code with input RTF string.

     

    string rtfString = @"{\rtf1\ansi\ansicpg1252\deff0\deflang1033\deflangfe1033{\fonttbl{\f0\froman\fprq2\fcharset0 Times New Roman;}{\f1\fnil\fcharset2 Symbol;}}\b\fs24Test text.\b0\par}";

    //Get bytes from string, this is needed to create MemoryStream

    byte[] rtfBytes = Encoding.UTF8.GetBytes(rtfString);

    //Create memorystream

    MemoryStream rtfStream = new MemoryStream(rtfBytes);

    //Create document from stream

    Document rtfDoc = new Document(rtfStream);

    //Save document in WML format

    rtfDoc.Save(htmlStream, SaveFormat.WordML);

     

    See the following link for more information.

    http://www.aspose.com/documentation/file-format-components/aspose.words-for-.net-and-java/introducing-aspose-words.html

     

    WBR,

    Alex

View as RSS news feed in XML