Knowledgebase (2300)
In daily work, converting a Word document to other formats can be extremely frequent. For example, sometimes you may need to convert a Word document to XML to store and organize data; on some occasions, you may also need to convert Word to SVG for sharing graphics contents on the Internet. In this article, you will learn how to convert Word to XPS, XML, RTF, TXT and SVG 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>13.11.2</version>
</dependency>
</dependencies>
Convert Word to XPS, XML, RTF, TXT and SVG
The following are the main steps to convert Word to XPS, XML, RTF, TXT and SVG.
- Create a Document object.
- Load the document using Document.loadFromFile() method.
- Use Document.saveToFile() method to save the document 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);
}
}
The original Word file:

The generated XPS file:

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 HTML (Hyper Text Markup Language) file is a webpage coded in HTML that can be displayed in a Web browser. It is widely used on the Web as most static webpages have an .html extension. In some cases, you need to convert some document formats (such as Word) to HTML. This tutorial will demonstrate how to convert Word to HTML 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>13.11.2</version>
</dependency>
</dependencies>
Convert Word to HTML
Spire.Doc for Java can easily convert Word to HTML using Document.saveToFile() method. You can find the steps as blow.
- Create a Document instance.
- Load a Word document using Document.loadFromFile() method.
- Save the document as an HTML file using Document.saveToFile() method.
- Java
import com.spire.doc.*;
public class WordToHtml {
public static void main(String[] args) {
//Create a Document instance
Document document = new Document();
//Load a Word document
document.loadFromFile("C:\\Users\\Test1\\Desktop\\sample.docx");
//Save the document as HTML
document.saveToFile("output/toHtml.html", FileFormat.Html);
}
}

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.
PDF Annotations are additional objects added to a PDF document. Sometimes you may need to extract these additional data from the PDF file so as to learn about the annotation details without opening the document. In this article, we will describe how to get the annotations from PDF in Java using Spire.PDF for Java.
Install Spire.PDF for Java
First of all, you need to add the Spire.PDF.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 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.pdf</artifactId>
<version>11.11.11</version>
</dependency>
</dependencies>
Get Annotations from a PDF File
Spire.PDF for Java offers PdfPageBase.getAnnotationsWidget() method to get the annotation collection of the specified page of the document.
The following are the steps to get all the annotations from the first page of PDF file:
- Create an object of PdfDocument class.
- Load a sample PDF document using PdfDocument.loadFromFile() method.
- Create a StringBuilder object.
- Get the annotation collection of the first page of the document by using PdfPageBase.getAnnotationsWidget() method.
- Loop through the pop-up annotations, after extract data from each annotation using PdfAnnotation.getText()method, then append the data to the StringBuilder instance using StringBuilder.append() method.
- Write the extracted data to a txt document using Writer.write() method.
- Java
import com.spire.pdf.*;
import com.spire.pdf.annotations.*;
import java.io.FileWriter;
public class Test {
public static void main(String[] args) throws Exception {
//Create an object of PdfDocument class.
PdfDocument pdf = new PdfDocument();
//Load the sample PDF document
pdf.loadFromFile("Annotations.pdf");
//Get the annotation collection of the first page of the document.
PdfAnnotationCollection annotations = pdf.getPages().get(0).getAnnotationsWidget();
//Create a StringBuilder object
StringBuilder content = new StringBuilder();
//Traverse all the annotations
for (int i = 0; i < annotations.getCount(); i++) {
//If it is the pop-up annotations, continue
if (annotations.get(i) instanceof PdfPopupAnnotationWidget)
continue;
//Get the annotations’ author
content.append("Annotation Author: " + annotations.get(i).getAuthor()+"\n");
//Get the annotations’ text
content.append("Annotation Text: " + annotations.get(i).getText()+"\n");
//Get the annotations’ modified date
String modifiedDate = annotations.get(i).getModifiedDate().toString();
content.append("Annotation ModifiedDate: " + modifiedDate+"\n");
//Get the annotations’ name
content.append("Annotation Name: " + annotations.get(i).getName()+"\n");
//Get the annotations’ location
content.append ("Annotation Location: " + annotations.get(i).getLocation()+"\n");
}
//Write to a .txt file
FileWriter fw = new FileWriter("GetAnnotations.txt");
fw.write(content.toString());
fw.flush();
fw.close();
}
}

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.