Java: Convert RTF to PDF

RTF (Rich Text Format) is a proprietary file format developed by Microsoft for cross-platform document interchange. RTF files have good compatibility and they can be opened by most word processors on any operating system such as Unix, Macintosh, and Windows. In some cases, you may need to convert RTF to other file formats to meet different requirements. In this article, you will learn how to convert RTF to PDF programmatically 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>12.3.1</version>
    </dependency>
</dependencies>
    

Convert RTF to PDF in Java

The detailed steps are as follows.

  • Create a Document instance.
  • Load a sample RTF document using Document.loadFromFile() method.
  • Save the RTF to PDF using Document.saveToFile() method.
  • Java
import com.spire.doc.*;

public class RTFToPDF {
    public static void main(String[] args) {

        //Create Document instance.
        Document document = new Document();

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

        //Save the document to PDF
        document.saveToFile("rtfToPdf.pdf", FileFormat.PDF);
    }
}

Java: Convert RTF to PDF

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.