Before you email or share an ODT file with others, you may want to convert the file to PDF in order to make it accessible to anyone across multiple operating systems. In this article, you will learn how to convert ODT to PDF in Java 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.10.3</version> </dependency> </dependencies>
Convert ODT to PDF using Java
The following are the steps to convert an ODT file to PDF:
- Create an instance of Document class.
- Load an ODT file using Document.loadFromFile() method.
- Convert the ODT file to PDF using Document.saveToFile(String fileName, FileFormat fileFormat) method.
- Java
import com.spire.doc.Document; import com.spire.doc.FileFormat; public class ConvertOdtToPdf { public static void main(String[] args){ //Create a Document instance Document doc = new Document(); //Load an ODT file doc.loadFromFile("Sample.odt"); //Save the ODT file to PDF doc.saveToFile("OdtToPDF.pdf", FileFormat.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.