Convert Word to XPS, XML, RTF, TXT and SVG with Spire.Doc for Java control

In daily work, converting Word documents to other formats is very frequent. For example, sometimes you may need to convert Word documents to XML to store and organize data; in some cases, you may also need to convert Word to SVG to share graphic content on the Internet. In this article, you will learn how to accomplish this task using Spire.Doc for Java .

Spire.Doc  is a class library specialized in operating Word documents. It helps developers create, edit, convert and print Microsoft Word documents easily, quickly and efficiently without installing Microsoft Word. With nearly 10 years of professional development experience, the Spire series of office document development tools focus on creating, editing, converting and printing Word/PDF/Excel and other format files. It is compact and convenient. In addition, you can also browse other products under E - iceblue  Document development tools in different languages~

Install Spire.Doc for Java

First, you need 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 into your application by adding the following code to your project's pom.xml file (qun:767755948)

<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>11.8.1</version>
</dependency>
</dependencies>
Convert Word to XPS, XML, RTF, TXT and SVG

Here are the main steps to convert Word to XPS, XML, RTF, TXT and SVG.

  • Create a document object.
  • Use the Document.loadFromFile() method to load the document.
  • Use the Document.saveToFile() method to save documents as SVG, RTF, XPS, XML and TXT respectively.

[JAVA]

import com.spire.doc.Document;
import com.spire.doc.FileFormat;
import com.spire.doc.documents.ImageType;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

public class ConvertWordToOtherFormats {

public static void main(String[] args) throws IOException {

//Create a Document object.
Document doc = new Document();

//Load the Word document.
doc.loadFromFile("C:\\Users\\Administrator\\Desktop\\sample.docx");

//Save Word as SVG.
doc.saveToFile("output/ToSVG.svg",FileFormat.SVG);

//Save Word as RTF.
doc.saveToFile("output/ToRTF.rtf",FileFormat.Rtf);

//Save Word as XPS.
doc.saveToFile("output/ToXPS.xps",FileFormat.XPS);

//Save Word as XML.
doc.saveToFile("output/ToXML.xml",FileFormat.Xml);

//Save Word as TXT.
doc.saveToFile("output/ToTXT.txt",FileFormat.Txt);
}
}

Original Word file:

Java: Convert Word to XPS, XML, RTF, TXT and SVG

Generated XPS file:

Java: Convert Word to XPS, XML, RTF, TXT and SVG

The above is how to convert Word to XPS, XML, RTF, TXT and SVG in Java. If you have other questions, you can continue to browse this series of articles and get related tutorials~

Guess you like

Origin blog.csdn.net/m0_67129275/article/details/132847877