none
Converting Word RTF documents to DOCX in word 2013/2016 using Wordcnvpxy.cnv Rtf2Foreign32 RRS feed

  • Question

  • Dear Sirs.

    Could you help me to how to use Wordcnvpxy.cnv 's function  Rtf2Foreign32 

    for Converting Word RTF documents to DOCX (word 2013/2016) using .NET

    Please share some code, and is this way faster than automation ?

    Thank you in Advance.

    Irakli Lomidze


    Irakli Lomidze

    Friday, April 1, 2016 12:28 PM

Answers

All replies

  • The necessary code for using that converter is built into Word itself. The simplest way of using it is to automate Word, open the RTF file, then use SaveAs2 to re-save the file in the docx format.

    Cheers
    Paul Edstein
    [MS MVP - Word]

    Saturday, April 2, 2016 5:32 AM
  • Hi, Irakli Lomidze

    Use the code below. It is worked as suggested by macropod. First it’s open the .RTF Document and then Save it to .DOCX Format.

    Dim oWord As Word.Application
            Dim oDoc As Word.Document
            Dim curDoc As Word.Document
            oWord = CreateObject("Word.Application")
            oWord.Visible = True
            oDoc = oWord.Documents.Open("C:\Users\Administrator\Desktop\docdemo.rtf")
            curDoc = oWord.ActiveDocument
            curDoc.SaveAs2(FileName:="C:\Users\Administrator\Desktop\docdemo1.docx", FileFormat:=WdSaveFormat.wdFormatXMLDocument)
    

    Regards

    Deepak


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, April 4, 2016 4:21 AM
    Moderator
  • Thank you for the code

    but this is automation code, that is slow for large volume of documents.

    I try to find Hi performance convert functions.

    And I'm rely surprise that native format for Word is RTF rather than DOCX.


    Irakli Lomidze

    Monday, April 4, 2016 5:36 AM
  • And I'm rely surprise that native format for Word is RTF rather than DOCX.

    The native format for Word documents has never been RTF. For Word 97-2003, it was Word's binary .doc format. For Word 2007 & later it's the XML Document format (file extension .docx).

    The following Word macro will convert all RTF files in a folder to the docx format. On my laptop, with a folder containing 50 RTF files totalling 113Mb, the conversion took 24 seconds.

    Sub RTF2DOCX()
    Application.ScreenUpdating = False
    Dim strFolder As String, strFile As String, wdDoc As Document
    strFolder = GetFolder
    If strFolder = "" Then Exit Sub
    strFile = Dir(strFolder & "\*.rtf", vbNormal)
    While strFile <> ""
      Set wdDoc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
      wdDoc.SaveAs2 FileName:=strFolder & "\" & Split(strFile, ".rtf")(0) & ".docx", Fileformat:=wdFormatXMLDocument, AddToRecentFiles:=False
      wdDoc.Close
      'Kill strFolder & "\" & strFile
      DoEvents
      strFile = Dir()
    Wend
    Set wdDoc = Nothing
    Application.ScreenUpdating = True
    End Sub
     
    Function GetFolder() As String
    Dim oFolder As Object
    GetFolder = ""
    Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
    If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
    Set oFolder = Nothing
    End Function

    There's a commented-out line to delete the converted RTF files, too, if you wish.


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Monday, April 4, 2016 6:18 AM
  • Dear Paul

    I have Experience of using Word Automation for converting RTF to DOCX using VBA and VSTO as well.

    But I have More than 250 000 Documents and I try to find faster way rather than automation.

    I find DLL in Word Installation Wordcnvpxy.cnv that has functions Rtf2Foreign32 and ForeigntoRTF32

    I hope that this functions has ability to do it with automation. like it works in server side of sharepoint (Word Automation Services) that is much faster than word VBA.



    Irakli Lomidze

    Wednesday, April 6, 2016 7:00 AM
  • Not familiar with Wordcnvpxy.cnv, but there are so many .NET component on market that are capable of converting .rtf file to .doc/.docx. I recommend you to try Spire.Doc with following code.

    Document doc = new Document();
    doc.LoadFromFile("sample.rtf", FileFormat.Rtf);
    doc.SaveToFile("result.docx", FileFormat.Docx);

    Thursday, April 7, 2016 2:59 AM
  • Somebody from the Microsoft Office team

    PLEASE PLEASE Break the Silence and give us some API

    You Told that Automation is not a reliable solution, OpenXML SDK does not support format Conversions

    What we should do ?

     

     


    Irakli Lomidze

    Wednesday, April 20, 2016 2:41 PM
  • Hi Irakli Lomidze,

    As you have a performance issue with the automation code that we have already provided to you.

    I will look in to this. If I find something better then that I will surely provide you as soon as possible.

    I will discuss with other support engineers and give you a appropriate response.

    Regards

    Deepak


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, April 21, 2016 4:51 AM
    Moderator
  • Using automation - which is quite reliable, I don't know who said otherwise - or just plain VBA, you could have completed this task multiple times by now.

    Cheers
    Paul Edstein
    [MS MVP - Word]

    Thursday, April 21, 2016 5:11 AM
  • Dear Paul

    Microsoft in every Developer Conference, give us Signal to avoid automation, using VBA or VSTO.

    And promoting new development model JS. 

    Also Automation is not supported on server mode, or in any untenanted processes.


    Irakli Lomidze

    Wednesday, April 27, 2016 7:42 AM
  • Is it any news for me ?

    Irakli Lomidze

    Wednesday, April 27, 2016 7:42 AM
  • Hi Irakli Lomidze,

    last time you have mentioned that you have a performance issue with automation code.

    here I want to asked you how you measure the performance of that code on particular document?

    how you determine that code has less performance.

    what is your desired performance for any particular document?

    Regards

    Deepak


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, April 27, 2016 7:50 AM
    Moderator
  • Microsoft in every Developer Conference, give us Signal to avoid automation, using VBA or VSTO.

    And promoting new development model JS. 

    Also Automation is not supported on server mode, or in any untenanted processes.

    It's hardly surprising that people at a Developer Conference might promote the tools they are familiar with or have a vested interest in.

    I can't comment on server mode, as I don't use it. I don't know what you mean by "any untenanted processes". If you're suggesting Automation is not supported in any unattended process, that simply is not true. I've left macros running unattended on very large projects overnight.


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Wednesday, April 27, 2016 8:18 AM
  • Dear Paul

    Sorry for my Misspelling.

    Here is a Statement from https://support.microsoft.com/en-us/kb/257757

    Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

    is VSTO still a recommended technology from Microsoft ? 



    Irakli Lomidze

    Wednesday, April 27, 2016 1:43 PM
  • That's all very well, but running a macro from within Word does not count for the purposes of that article.

    Without wanting to place too fine a point on the matter, you could have completed this project many times over by now had you used a macro such as the one I posted instead of continually debating the issue.


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Wednesday, April 27, 2016 10:10 PM
  • Hi Irakli Lomidze,

    did you try the suggestions given above?

    you have a performance issue right?

    but you did not tell us what are your standards of performance. in the above post you have asked

    is VSTO still a recommended technology from Microsoft ? 

    I would say "Yes".

    Regards

    Deepak


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, April 28, 2016 3:45 AM
    Moderator
  • Hi Deepak

    Currently I Use C# Code VSTO (Word Interop Assemblies) 

    I have compared it to VBA code, that is a bit faster.

    But question that I asked it avoid word automation and document rendering in conversion process.

    I believes that document conversion its possible without rendering it (except PDF and XPS cases).

    Also there is a Word Automation Services available only for SharePoint and performance of it much faster than automation.   

    Is there any way to avoid automation, and use some conversion DLL that MS word use internally. Like Wordcnvpxy.cnv.



    Irakli Lomidze

    Thursday, April 28, 2016 6:39 AM
  • Hi Irakli Lomidze,

    here one thing I am not understanding that how you measure a performance?

    so that if we know something about that then we can suggest you.

    because the ways we suggested and it not perform as per your desired performance then there is no meaning to suggest something.

    the thing you have mentioned about js development model. you want to use it ? but it is also automation.

    Regards

    Deepak


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, April 29, 2016 6:29 AM
    Moderator
  • Dear Deepak

    I mesure It comparison with performance of Word Automation Service (in Sharepoint).

    How WAS is so fast with comparison of automation Word Client ? (Converting RTF to PDF)

    In case of Word Client Automation.

    Load Method is:

    1) Load Document

    2) Convert in Internal Format

    3) Render it

    4) And SaveAs2

    5) Convert it Again in Desired Format

    Is it somehow possibility to avoid rendering ? and Convert it directly format to format.

    I guess that only PDF and XPS Converting requires Rendering prior converting.

    Thank you in Advance.

     



    Irakli Lomidze

    Monday, May 2, 2016 8:22 PM
  • In case of Word Client Automation.

    Load Method is:

    1) Load Document

    2) Convert in Internal Format

    3) Render it

    4) And SaveAs2

    5) Convert it Again in Desired Format

    Is it somehow possibility to avoid rendering ?

    Perhaps you should look at the code I posted. In my code, your step 3 is not used (screen updating is turned off and the document is never made visible) and your Step 5 is actually part of Step 4, not a separate process. Likewise your Steps 1 & 2 are a single process in my code.

    Cheers
    Paul Edstein
    [MS MVP - Word]

    Tuesday, May 3, 2016 1:13 AM
  • Hi Irakli Lomidze,

    did you make a test with code posted by the macropod?

    it's look like that match with your requrements.

    can you please check it.

    Regards

    Deepak


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, May 3, 2016 3:16 AM
    Moderator
  • Yes I Did. as sad previously.


    Irakli Lomidze

    Tuesday, May 3, 2016 6:58 AM
  • Hi Irakli Lomidze,

    I will check the Word Automation Service (in Sharepoint).I will provide you if I find some useful information.

    Regards

    Deepak 


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, May 3, 2016 7:06 AM
    Moderator
  • Hello Deepak

    Is it any news for me ?


    Irakli Lomidze

    Sunday, July 3, 2016 11:53 AM
  • Hi Irakli Lomidze,

    yes I had check this issue again. I had a discussion with my team and also with sharepoint team.

    The information you had asked regarding Word Automation Service (in SharePoint) is not supported by our forum.

    we had already provided you a solution that we can do with word object model.

    then also I try to find regarding this issue and find the links below.

    Word Automation Services in SharePoint Server 2010

    Word Automation Services Overview

    Programming Word Automation Services

    Word Automation Services Object Model

    ConversionJob Class

    ConversionJob Methods

    ConversionJob Constructor

    ConversionJob Properties

    in the link below you will get example how to convert document to pdf using Word Automation Services

    Document Conversion with Word Automation Services

    if still your issue not solved by this suggestion then I would recommend you to create a new thread on the forum mentioned below. this Forum supports the issue regarding  Word Automation Services.

    SharePoint 2013 - Development and Programming

    As this topic is not related with our Forum I recommended you to create a new thread on that forum.

    Disclaimer: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

    Hope this helps you to solve your issue.

    Regards

    Deepak


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, July 5, 2016 6:29 AM
    Moderator