Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 730941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:58:09+00:00 2026-05-14T06:58:09+00:00

I am in a need of programatically convert an Word-XML file into a RTF

  • 0

I am in a need of programatically convert an Word-XML file into a RTF file. It has become a requirement, because of some third party libraries. Any API/Library that can do that?

Actually the language is not a problem because I just need to work done. But Java, .NET languages or Python are preferred.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T06:58:10+00:00Added an answer on May 14, 2026 at 6:58 am

    A Python/linux way:

    You need the OpenOffice Uno Bride (On server you could run OO in headless mode).
    As a result you can convert every OO-readable format to every OO-writeable:

    see http://wiki.services.openoffice.org/wiki/Framework/Article/Filter/FilterList_OOo_3_0

    Run Example Code

    /usr/lib64/openoffice.org/program/soffice.bin -accept=socket,host=localhost,port=8100\;urp -headless
    

    Python Example:

    import uno
    from os.path import abspath, isfile, splitext
    from com.sun.star.beans import PropertyValue
    from com.sun.star.task import ErrorCodeIOException
    from com.sun.star.connection import NoConnectException
    
    FAMILY_TEXT = "Text"
    FAMILY_SPREADSHEET = "Spreadsheet"
    FAMILY_PRESENTATION = "Presentation"
    FAMILY_DRAWING = "Drawing"
    DEFAULT_OPENOFFICE_PORT = 8100
    
    FILTER_MAP = {
        "pdf": {
            FAMILY_TEXT: "writer_pdf_Export",
            FAMILY_SPREADSHEET: "calc_pdf_Export",
            FAMILY_PRESENTATION: "impress_pdf_Export",
            FAMILY_DRAWING: "draw_pdf_Export"
        },
        "html": {
            FAMILY_TEXT: "HTML (StarWriter)",
            FAMILY_SPREADSHEET: "HTML (StarCalc)",
            FAMILY_PRESENTATION: "impress_html_Export"
        },
        "odt": { FAMILY_TEXT: "writer8" },
        "doc": { FAMILY_TEXT: "MS Word 97" },
        "rtf": { FAMILY_TEXT: "Rich Text Format" },
        "txt": { FAMILY_TEXT: "Text" },
        "docx": { FAMILY_TEXT: "MS Word 2007 XML" },
        "ods": { FAMILY_SPREADSHEET: "calc8" },
        "xls": { FAMILY_SPREADSHEET: "MS Excel 97" },
        "odp": { FAMILY_PRESENTATION: "impress8" },
        "ppt": { FAMILY_PRESENTATION: "MS PowerPoint 97" },
        "swf": { FAMILY_PRESENTATION: "impress_flash_Export" }
    }
    
    class DocumentConverter:
    
        def __init__(self, port=DEFAULT_OPENOFFICE_PORT):
            localContext = uno.getComponentContext()
            resolver = localContext.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", localContext)
            try:
                self.context = resolver.resolve("uno:socket,host=localhost,port=%s;urp;StarOffice.ComponentContext" % port)
            except NoConnectException:
                raise Exception, "failed to connect to OpenOffice.org on port %s" % port
            self.desktop = self.context.ServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop", self.context)
    
        def convert(self, inputFile, outputFile):
    
            inputUrl = self._toFileUrl(inputFile)
            outputUrl = self._toFileUrl(outputFile)
    
            document = self.desktop.loadComponentFromURL(inputUrl, "_blank", 0, self._toProperties(Hidden=True))
            #document.setPropertyValue("DocumentTitle", "saf" ) TODO: Check how this can be set and set doc update mode to  FULL_UPDATE
    
            if self._detectFamily(document) == FAMILY_TEXT:
                indexes = document.getDocumentIndexes()
                for i in range(0, indexes.getCount()):
                    index = indexes.getByIndex(i)
                    index.update()
    
                try:
                    document.refresh()
                except AttributeError:
                    pass
    
                indexes = document.getDocumentIndexes()
                for i in range(0, indexes.getCount()):
                    index = indexes.getByIndex(i)
                    index.update()
    
            outputExt = self._getFileExt(outputFile)
            filterName = self._filterName(document, outputExt)
    
            try:
                document.storeToURL(outputUrl, self._toProperties(FilterName=filterName))
            finally:
                document.close(True)
    
        def _filterName(self, document, outputExt):
            family = self._detectFamily(document)
            try:
                filterByFamily = FILTER_MAP[outputExt]
            except KeyError:
                raise Exception, "unknown output format: '%s'" % outputExt
            try:
                return filterByFamily[family]
            except KeyError:
                raise Exception, "unsupported conversion: from '%s' to '%s'" % (family, outputExt)
    
        def _detectFamily(self, document):
            if document.supportsService("com.sun.star.text.GenericTextDocument"):
                # NOTE: a GenericTextDocument is either a TextDocument, a WebDocument, or a GlobalDocument
                # but this further distinction doesn't seem to matter for conversions
                return FAMILY_TEXT
            if document.supportsService("com.sun.star.sheet.SpreadsheetDocument"):
                return FAMILY_SPREADSHEET
            if document.supportsService("com.sun.star.presentation.PresentationDocument"):
                return FAMILY_PRESENTATION
            if document.supportsService("com.sun.star.drawing.DrawingDocument"):
                return FAMILY_DRAWING
            raise Exception, "unknown document family: %s" % document
    
        def _getFileExt(self, path):
            ext = splitext(path)[1]
            if ext is not None:
                return ext[1:].lower()
    
        def _toFileUrl(self, path):
            return uno.systemPathToFileUrl(abspath(path))
    
        def _toProperties(self, **args):
            props = []
            for key in args:
                prop = PropertyValue()
                prop.Name = key
                prop.Value = args[key]
                props.append(prop)
            return tuple(props)
    
    if __name__ == "__main__":
        from sys import argv, exit
    
        if len(argv) < 3:
            print "USAGE: python %s <input-file> <output-file>" % argv[0]
            exit(255)
        if not isfile(argv[1]):
            print "no such input file: %s" % argv[1]
            exit(1)
    
        try:
            converter = DocumentConverter()    
            converter.convert(argv[1], argv[2])
        except Exception, exception:
            print "ERROR!" + str(exception)
            exit(1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.