JODConverter automates document conversions using LibreOffice or Apache OpenOffice.
See the code
JODConverter, the Java OpenDocument Converter, converts documents between office formats: Word, Excel, PowerPoint, OpenDocument, PDF, HTML, images and many more. It drives a LibreOffice or Apache OpenOffice installation, so it converts whatever that office converts.
It can be used:
📖 Documentation · Release notes · FAQ · Samples
| JODConverter | Java | Spring Boot |
|---|---|---|
| 5.x | 17+ | 4.x |
| 4.4.x | 8+ | 2.x and 3.x |
Coming from 4.4? See the migration guide.
Add the library, here for LibreOffice (see the modules for the other ones):
<dependency>
<groupId>org.jodconverter</groupId>
<artifactId>jodconverter-local-lo</artifactId>
<version>5.1.1</version>
</dependency>
implementation("org.jodconverter:jodconverter-local-lo:5.1.1")
Then start an office manager once, and convert:
import java.io.File;
import org.jodconverter.core.office.OfficeUtils;
import org.jodconverter.local.JodConverter;
import org.jodconverter.local.office.LocalOfficeManager;
public class Example {
public static void main(String[] args) throws Exception {
// Starts an office process, found in its default location, and keeps it for all the conversions.
LocalOfficeManager officeManager = LocalOfficeManager.install();
try {
officeManager.start();
// The formats are those of the file extensions.
JodConverter.convert(new File("document.docx")).to(new File("document.pdf")).execute();
} finally {
OfficeUtils.stopQuietly(officeManager);
}
}
}
An office manager is meant to live as long as the application, and to be shared by all its conversions: starting an office process costs much more than a conversion.
Add the starter next to the library:
implementation("org.jodconverter:jodconverter-spring-boot-starter:5.1.1")
implementation("org.jodconverter:jodconverter-local-lo:5.1.1")
enable it:
jodconverter.local.enabled=true
and inject the converter where you need it:
@Service
public class ReportService {
private final DocumentConverter converter;
public ReportService(DocumentConverter converter) {
this.converter = converter;
}
public void toPdf(File source, File target) throws OfficeException {
converter.convert(source).to(target).execute();
}
}
Download jodconverter-cli from the latest release, unpack it, then:
bin/jodconverter-cli document.docx document.pdf
(bin\jodconverter-cli.bat on Windows.)
JODConverter is licensed under the Apache License, Version 2.0.
JODConverter automates document conversions using LibreOffice or Apache OpenOffice.
See the code
JODConverter, the Java OpenDocument Converter, converts documents between office formats: Word, Excel, PowerPoint, OpenDocument, PDF, HTML, images and many more. It drives a LibreOffice or Apache OpenOffice installation, so it converts whatever that office converts.
It can be used:
📖 Documentation · Release notes · FAQ · Samples
| JODConverter | Java | Spring Boot |
|---|---|---|
| 5.x | 17+ | 4.x |
| 4.4.x | 8+ | 2.x and 3.x |
Coming from 4.4? See the migration guide.
Add the library, here for LibreOffice (see the modules for the other ones):
<dependency>
<groupId>org.jodconverter</groupId>
<artifactId>jodconverter-local-lo</artifactId>
<version>5.1.1</version>
</dependency>
implementation("org.jodconverter:jodconverter-local-lo:5.1.1")
Then start an office manager once, and convert:
import java.io.File;
import org.jodconverter.core.office.OfficeUtils;
import org.jodconverter.local.JodConverter;
import org.jodconverter.local.office.LocalOfficeManager;
public class Example {
public static void main(String[] args) throws Exception {
// Starts an office process, found in its default location, and keeps it for all the conversions.
LocalOfficeManager officeManager = LocalOfficeManager.install();
try {
officeManager.start();
// The formats are those of the file extensions.
JodConverter.convert(new File("document.docx")).to(new File("document.pdf")).execute();
} finally {
OfficeUtils.stopQuietly(officeManager);
}
}
}
An office manager is meant to live as long as the application, and to be shared by all its conversions: starting an office process costs much more than a conversion.
Add the starter next to the library:
implementation("org.jodconverter:jodconverter-spring-boot-starter:5.1.1")
implementation("org.jodconverter:jodconverter-local-lo:5.1.1")
enable it:
jodconverter.local.enabled=true
and inject the converter where you need it:
@Service
public class ReportService {
private final DocumentConverter converter;
public ReportService(DocumentConverter converter) {
this.converter = converter;
}
public void toPdf(File source, File target) throws OfficeException {
converter.convert(source).to(target).execute();
}
}
Download jodconverter-cli from the latest release, unpack it, then:
bin/jodconverter-cli document.docx document.pdf
(bin\jodconverter-cli.bat on Windows.)
JODConverter is licensed under the Apache License, Version 2.0.