<dependencies>
<dependency>
<groupId>org.jodconverter</groupId>
<artifactId>jodconverter-local</artifactId>
<version>4.4.7</version>
</dependency>
......
</dependencies>
We are trying to use the combination of jodconvert and OpenOffice tools in the development of the Confluence plugin to solve the problem of some Office files not being previewed in Confluence. This problem may be caused by manual modification of file suffixes, file encryption, etc.
Previously, we attempted POI, but the style and font issues were too severe and could not be resolved in a short period of time. Therefore, we decided to try using the jodconvert+OpenOffice tool combination. We confirmed that this tool combination works properly in a non plugin environment. When we tried to migrate to the plugin, Confluence threw the following exception:
The instructions configuration information in pom.xml is as follows:
<instructions>
<Atlassian-Plugin-Key>${atlassian.plugin.key}</Atlassian-Plugin-Key>
<!-- Add package to export here -->
<Export-Package>
</Export-Package>
<!-- Add package import here -->
<Import-Package>
*;version="0";resolution:=optional
</Import-Package>
<!-- Ensure plugin is spring powered -->
<Spring-Context>*</Spring-Context>
</instructions>
The usage of jodconverter is as follows:
public static boolean officeToPDF(String sourceFile, String destFile) {
final LocalOfficeManager officeManager = LocalOfficeManager.install();
try {
File inputFile = new File(sourceFile);
if (!inputFile.exists()) {
return false;
}
File outputFile = new File(destFile);
if (!outputFile.getParentFile().exists()) {
outputFile.getParentFile().mkdirs();
}
if (outputFile.exists()) {
outputFile.delete();
}
officeManager.start();
long l = System.currentTimeMillis();
JodConverter
.convert(inputFile)
.to(outputFile)
.execute();
System.out.println("time usage:" + (System.currentTimeMillis() - l));
return true;
} catch (Exception e) {
e.printStackTrace();
} finally {
OfficeUtils.stopQuietly(officeManager);
}
return false;
}