RTF, short for Rich Text Format, is created by Microsoft in 1987 for the purpose of cross-platform document interchange. It is supported by many word processing applications, and the most popular one among them is Microsoft Word. In certain circumstances, you may need to convert an RTF document to Word Doc/Docx format or convert a Word Doc/Docx document to RTF. In this article, you will learn how to accomplish this task using Spire.Doc for Java.

Install Spire.Doc for Java

First of all, you're required to add the Spire.Doc.jar file as a dependency in your Java program. The JAR file can be downloaded from this link. If you use Maven, you can easily import the JAR file in your application by adding the following code to your project's pom.xml file.

<repositories>
    <repository>
        <id>com.e-iceblue</id>
        <name>e-iceblue</name>
        <url>https://repo.e-iceblue.com/nexus/content/groups/public/</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>e-iceblue</groupId>
        <artifactId>spire.doc</artifactId>
        <version>14.6.0</version>
    </dependency>
</dependencies>

Convert RTF to Word Doc/Docx

The following are the steps to convert an RTF document to Word Doc/Docx using Spire.Doc for Java:

  • Create a Document instance.
  • Load an RTF document using Document.loadFromFile(String, FileFormat) method.
  • Save the RTF to Doc/Docx format using Document.saveToFile(String, FileFormat) method.
  • Java
import com.spire.doc.Document;
import com.spire.doc.FileFormat;

public class RtfToDocDocx {
    public static void main(String[] args){
        //Create a Document instance
        Document document = new Document();

        //Load a RTF document
        document.loadFromFile("Input.rtf", FileFormat.Rtf);

        //Save the document to Doc
        document.saveToFile("toDoc.doc", FileFormat.Doc);

        //Save the document to Docx
        document.saveToFile("toDocx.docx", FileFormat.Docx_2013);
    }
}

Java: Convert RTF to Word Doc/Docx and Vice Versa

Convert Word Doc/Docx to RTF

The steps to convert a Word Doc/Docx document to RTF is very similar with that of the above example:

  • Create a Document instance.
  • Load a Doc or Docx document using Document.loadFromFile(String) method.
  • Save the Doc/Docx document to RTF using Document.saveToFile(String, FileFormat) method.
  • Java
import com.spire.doc.Document;
import com.spire.doc.FileFormat;

public class DocDocxToRtf {
    public static void main(String[] args){
        //Create a Document instance
        Document document = new Document();

        //Load a Docx document
        document.loadFromFile("input.docx");

        //Load a Doc document
        //document.loadFromFile("sample.doc");

        //Save the document to RTF
        document.saveToFile("toRTF.rtf", FileFormat.Rtf);
    }
}

Java: Convert RTF to Word Doc/Docx and Vice Versa

Apply for a Temporary License

If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.

An Excel document with Track Changes turned on will let you know what changes have been made to the document since the author has saved it. If you have the full authority over the document, you can accept or reject each revision. This article covers how to accept or reject all tracked changes at once using Spire.XLS for Java.

Install Spire.XLS for Java

First of all, you're required to add the Spire.Xls.jar file as a dependency in your Java program. The JAR file can be downloaded from this link. If you use Maven, you can easily import the JAR file in your application by adding the following code to your project's pom.xml file.

<repositories>
    <repository>
        <id>com.e-iceblue</id>
        <name>e-iceblue</name>
        <url>https://repo.e-iceblue.com/nexus/content/groups/public/</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>e-iceblue</groupId>
        <artifactId>spire.xls</artifactId>
        <version>16.6.5</version>
    </dependency>
</dependencies>

Accept Tracked Changes in a Workbook

To determine whether a workbook has tracked changes, use Workbook.hasTrackedChanegs() method. If yes, you can accept all changes at once using Workbook.acceptAllTrackedchanges() method. The following are the steps to accept tracked changes in an Excel workbook.

  • Create a Workbook object.
  • Load the sample Excel document using Workbook.loadFromFile() method.
  • Determine if the workbook has tracked changes by Workbook.hasTrackedChanegs() method.
  • Accept tracked changes using Workbook.acceptAllTrackedChanges() method.
  • Save the document to another file using Workbook.saveToFile() method.
  • Java
import com.spire.xls.FileFormat;
import com.spire.xls.Workbook;

public class AcceptTrackedChanges {

    public static void main(String[] args) {

        //Create a Workbook object
        Workbook wb = new Workbook();

        //Load the sample Excel file
        wb.loadFromFile("C:\\Users\\Administrator\\Desktop\\Employees.xlsx");

        //Determine if the workbook has tracked changes
        if (wb.hasTrackedChanges())
        {
            //Accept tracked changes in the workbook
            wb.acceptAllTrackedChanges();
        }

        //Save to file
        wb.saveToFile("output/AcceptChanges.xlsx", FileFormat.Version2013);
    }
}

Java: Accept or Reject Tracked Changes in Excel

Reject Tracked Changes in a Workbook

If the tracked changes have been proven to exist in a workbook, you can reject them using Workbook.rejectAllTrackedChanges() method. The following are the steps to achieve this.

  • Create a Workbook object.
  • Load the sample Excel document using Workbook.loadFromFile() method.
  • Determine if the workbook has tracked changes by Workbook.hasTrackedChanegs() method.
  • Reject all tracked changes using Workbook.rejectAllTrackedChanges() method.
  • Save the document to another file using Workbook.saveToFile() method.
  • Java
import com.spire.xls.FileFormat;
import com.spire.xls.Workbook;

public class RejectTrackedChanges {

    public static void main(String[] args) {

        //Create a Workbook object
        Workbook wb = new Workbook();

        //Load the sample Excel file
        wb.loadFromFile("C:\\Users\\Administrator\\Desktop\\Employees.xlsx");

        //Determine if the workbook has tracked changes
        if (wb.hasTrackedChanges())
        {
            //Reject tracked changes in the workbook
            wb.rejectAllTrackedChanges();
        }

        //Save to file
        wb.saveToFile("output/RejectChanges.xlsx", FileFormat.Version2013);
    }
}

Java: Accept or Reject Tracked Changes in Excel

Apply for a Temporary License

If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.

LaTeX is a powerful tool to typeset mathematical equations. It supports plenty of mathematical symbols and notations to create mathematical equations, for instance, fractions, integrals and more.

Spire.Presentation API provides developers with the ability to create and add mathematical equations to PowerPoint shape using LaTeX code. The following steps demonstrate how to achieve this function using Spire.Presentation:

  • Create a Presentation instance.
  • Get the reference of a slide by using its index.
  • Use ShapeList.AppendShape method to add a shape to the first slide.
  • Use ParagraphCollection.AddParagraphFromLatexMathCode(string) method to create a mathematical equation from LaTeX code and add it to the shape.
  • Save the result document using Presentation.SaveToFile(string, FileFormat) method.

The following code shows how to add mathematical equations to PowerPoint in C#.

using Spire.Presentation;
using System.Drawing;

namespace MathEquations
{
    class Program
    {
        static void Main(string[] args)
        {            
            //The LaTeX codes
            string latexCode1 = @"x^{2} + \sqrt{x^{2}+1}=2";
            string latexCode2 = @"F(x) &= \int^a_b \frac{1}{3}x^3";
            string latexCode3 = @"\alpha + \beta  \geq \gamma";
            string latexCode4 = @"\overrightarrow{abc}";
            string latexCode5 = @"\begin{bmatrix} 1 & 0 & \cdots & 0\\ 1 & 0 & \cdots & 0\\ \vdots & \vdots & \ddots & \vdots\\ 1 & 0 & 0 & 0 \end{bmatrix}";
            string latexCode6 = @"\log_a{b}";

            //Create a Presentation instance
            Presentation ppt = new Presentation();

            //Get the first slide by using its index
            ISlide slide = ppt.Slides[0];

            //Add a shape to the slide
            IAutoShape shape = slide.Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(30, 100, 200, 30));
            shape.TextFrame.Paragraphs.Clear();
            //Add a math equation to the shape using the LaTeX code 
            shape.TextFrame.Paragraphs.AddParagraphFromLatexMathCode(latexCode1);

            //Add a shape to the slide
            shape = slide.Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(240, 100, 200, 40));
            shape.TextFrame.Paragraphs.Clear();
            //Add a math equation to the shape using the LaTeX code 
            shape.TextFrame.Paragraphs.AddParagraphFromLatexMathCode(latexCode2);

            //Add a shape to the slide
            shape = slide.Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(30, 180, 200, 40));
            shape.TextFrame.Paragraphs.Clear();
            //Add a math equation to the shape using the LaTeX code 
            shape.TextFrame.Paragraphs.AddParagraphFromLatexMathCode(latexCode3);

            //Add a shape to the slide
            shape = slide.Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(240, 180, 200, 40));
            shape.TextFrame.Paragraphs.Clear();
            //Add a math equation to the shape using the LaTeX code 
            shape.TextFrame.Paragraphs.AddParagraphFromLatexMathCode(latexCode4);

            //Add a shape to the slide
            shape = slide.Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(30, 280, 200, 70));
            shape.TextFrame.Paragraphs.Clear();
            //Add a math equation to the shape using the LaTeX code 
            shape.TextFrame.Paragraphs.AddParagraphFromLatexMathCode(latexCode5);

            //Add a shape to the slide
            shape = slide.Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(240, 280, 200, 40));
            shape.TextFrame.Paragraphs.Clear();
            //Add a math equation to the shape using the LaTeX code 
            shape.TextFrame.Paragraphs.AddParagraphFromLatexMathCode(latexCode6);

            for (int i = 0; i < slide.Shapes.Count; i++)
            {
                slide.Shapes[i].Fill.FillType = Spire.Presentation.Drawing.FillFormatType.None;
                slide.Shapes[i].Line.FillType = Spire.Presentation.Drawing.FillFormatType.None;
            }

            //Save the result document
            ppt.SaveToFile("MathEquations.pptx", FileFormat.Pptx2013);
        }
    }
}

The following code shows how to add mathematical equations to PowerPoint in VB.NET.

Imports Spire.Presentation
Imports System.Drawing

Namespace MathEquations
    Friend Class Program
        Private Shared Sub Main(ByVal args As String())
            'The LaTeX codes
            Dim latexCode1 As String = "x^{2} + \sqrt{x^{2}+1}=2"
            Dim latexCode2 As String = "F(x) &= \int^a_b \frac{1}{3}x^3"
            Dim latexCode3 As String = "\alpha + \beta  \geq \gamma"
            Dim latexCode4 As String = "\overrightarrow{abc}"
            Dim latexCode5 As String = "\begin{bmatrix} 1 & 0 & \cdots & 0\\ 1 & 0 & \cdots & 0\\ \vdots & \vdots & \ddots & \vdots\\ 1 & 0 & 0 & 0 \end{bmatrix}"
            Dim latexCode6 As String = "\log_a{b}"

            'Create a Presentation instance
            Dim ppt As Presentation = New Presentation()

            'Get the first slide by using its index
            Dim slide As ISlide = ppt.Slides(0)

            'Add a shape to the slide
            Dim shape As IAutoShape = slide.Shapes.AppendShape(ShapeType.Rectangle, New RectangleF(30, 100, 200, 30))
            shape.TextFrame.Paragraphs.Clear()
            'Add a math equation to the shape using the LaTeX code 
            shape.TextFrame.Paragraphs.AddParagraphFromLatexMathCode(latexCode1)

            'Add a shape to the slide
            shape = slide.Shapes.AppendShape(ShapeType.Rectangle, New RectangleF(240, 100, 200, 40))
            shape.TextFrame.Paragraphs.Clear()
            'Add a math equation to the shape using the LaTeX code 
            shape.TextFrame.Paragraphs.AddParagraphFromLatexMathCode(latexCode2)

            'Add a shape to the slide
            shape = slide.Shapes.AppendShape(ShapeType.Rectangle, New RectangleF(30, 180, 200, 40))
            shape.TextFrame.Paragraphs.Clear()
            'Add a math equation to the shape using the LaTeX code 
            shape.TextFrame.Paragraphs.AddParagraphFromLatexMathCode(latexCode3)

            'Add a shape to the slide
            shape = slide.Shapes.AppendShape(ShapeType.Rectangle, New RectangleF(240, 180, 200, 40))
            shape.TextFrame.Paragraphs.Clear()
            'Add a math equation to the shape using the LaTeX code 
            shape.TextFrame.Paragraphs.AddParagraphFromLatexMathCode(latexCode4)

            'Add a shape to the slide
            shape = slide.Shapes.AppendShape(ShapeType.Rectangle, New RectangleF(30, 280, 200, 70))
            shape.TextFrame.Paragraphs.Clear()
            'Add a math equation to the shape using the LaTeX code 
            shape.TextFrame.Paragraphs.AddParagraphFromLatexMathCode(latexCode5)

            'Add a shape to the slide
            shape = slide.Shapes.AppendShape(ShapeType.Rectangle, New RectangleF(240, 280, 200, 40))
            shape.TextFrame.Paragraphs.Clear()
            'Add a math equation to the shape using the LaTeX code 
            shape.TextFrame.Paragraphs.AddParagraphFromLatexMathCode(latexCode6)

            For i As Integer = 0 To slide.Shapes.Count - 1
                slide.Shapes(i).Fill.FillType = Spire.Presentation.Drawing.FillFormatType.None
                slide.Shapes(i).Line.FillType = Spire.Presentation.Drawing.FillFormatType.None
            Next

            'Save the result document
            ppt.SaveToFile("MathEquations.pptx", FileFormat.Pptx2013)
        End Sub
    End Class
End Namespace

The following is the output document after adding mathematical equations:

Add Math Equations to PowerPoint using LaTeX Code in C#, VB.NET

Apply for a Temporary License

If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.

page 114