How programmatically convert between DOCX and RTF in C# using Document .Net library?
 
PRODUCTS   DOWNLOAD PURCHASE SUPPORT BLOG  COMPANY  
 
Overview
Download
Purchase
Code Examples
Create
Load
Save as
Convert
Merge
Digital Signature
PDF/A Compliance
Protect and Security
Document Properties
Find and Replace
Reporting and Mail Merge
API Reference
Version History

"How programmatically convert between DOCX and RTF in C# using Document .Net library?"

Introduction

If you are looking for a solution to programmatically convert DOCX to RTF and vice versa in C# or VB.Net, you are in the right place!

How programmatically convert between DOCX and RTF in C# using Document .Net library?
  • Document .Net library is written in 100% managed C#
  • DOCX - Office Open XML, ECMA-376
  • RTF - Rich Text Format Specification 1.8
  • All features are supported
  • No MS Office Automation

Document .Net is 100% managed C# assembly (SautinSoft.Document.dll) which gives you API to load, parse and create DOCX and RTF documents.

The library is absolutely standalone and does not require Microsoft Office or any others.

Performance

At a machine with Intel Core i5-3337U and 4GB of RAM the Document .Net generates a simple DOCX document (one page filled by formatted text) without saving it to HDD:

  • 1000 documents by 0.45 sec.
  • 10000 documents by 3.61 sec.

Implementation and code samples

To get the full set of API to operate with DOCX or RTF, you have to only add a reference to "SautinSoft.Document.dll"".

It's easy to add reference to SautinSoft.Document.dll

1. Example 1: Convert DOCX to RTF in C# application:

using System;
using System.IO;
using SautinSoft.Document;

namespace Sample
{
    class Program
    {
        static void Main(string[] args)
        {
            // Step 1: Load a docx document.
            DocumentCore dc = DocumentCore.Load(@"d:\Paper.docx", LoadOptions.DocxDefault);

            // Step 2: Save the document to rtf format.
            dc.Save(@"d:\Paper.rtf", SaveOptions.RtfDefault);
        }
    }
}

2. Example 2: Convert RTF to DOCX in C# application:

using System;
using System.IO;
using SautinSoft.Document;

namespace Sample
{
    class Program
    {
        static void Main(string[] args)
        {
            // Step 1: Load a rtf document.
            DocumentCore dc = DocumentCore.Load(@"d:\Paper.rtf", LoadOptions.RtfDefault);

            // Step 2: Save the document to docx format.
            dc.Save(@"d:\Paper.docx", SaveOptions.DocxDefault);
        }
    }
}

3. Example 3: Loop between DOCX and RTF in C#:

using System;
using System.IO;
using System.Collections.Generic;
using SautinSoft.Document;

namespace Sample
{
    class Program
    {
        static void Main(string[] args)
        {
            // Working directory
            string startingPath = @"D:\Start.docx";

            // Set desired number of converting loops.
            int loops = 5;

            string workingDir = Path.GetDirectoryName(startingPath);
            string fileName = Path.GetFileName(startingPath);
            string name = Path.GetFileName(startingPath); ;
            string filePath = Path.Combine(workingDir, fileName);

            List<string> extns = new List<string>() { ".rtf", ".docx" };

            for (int i = 0; i < loops; i++)
            {
                DocumentCore dc = DocumentCore.Load(filePath);
                string extn = Path.GetExtension(fileName).ToLower();
                // invert extension
                int ind = extns.FindIndex((s) => (extn == s));
                extns.Reverse();
                extn = extns[ind];

                fileName = Path.GetFileNameWithoutExtension(name) + (i + 1).ToString() + extn;
                filePath = Path.Combine(workingDir, fileName);

                dc.Save(filePath);
                dc = null;
            }
        }
    }
}


Requirements and Technical Information

Document .Net is compatible with all .Net languages and supports all OS (Windows, MacOS and Linux) where .Net Framework or .Net Core can be used. It's entirely written in managed C#, which makes it absolutely standalone and independent.

.Net Framework 4.0 and higher and .Net Core 2.0 and higher

.Net Framework 4.0, 4.5, 4.6.1 and higher.

.Net Core 2.0 and higher.



Reasonable prices

     The library offers for developers comprehensive API to do all what they want with DOCX, RTF, HTML, PDF and Text formats at reasonably prices. The main point of interest is that «Document .Net» is less expensive than all of its more or less popular counterparts. For example, a single license of Document .Net - Standard Edition starts from $530.


Download

To see this functionality firsthand, download the freshest «Document .Net» with code examples, 38.2 Mb.

 

 
Products Support Company Contact

  • Sweden, Stockholm
  • Mortviksvagen 68B 142 43 SKOGAS
  • Sales & Support:
  • Tel: +46 766922352
  • Email:
  • sales@sautinsoft.com support@sautinsoft.com
  •       
    Copyright © 2002 - 2019 SautinSoft (started from sautin.com). All rights reserved.