online

pom

  1. <dependency>
  2. <groupId>org.jodconverter</groupId>
  3. <artifactId>jodconverter-core</artifactId>
  4. <version>4.2.2</version>
  5. </dependency>
  6. <!--springboot支持包,里面包括了自动配置类 -->
  7. <dependency>
  8. <groupId>org.jodconverter</groupId>
  9. <artifactId>jodconverter-spring-boot-starter</artifactId>
  10. <version>4.2.2</version>
  11. </dependency>
  12. <!-- https://mvnrepository.com/artifact/org.jodconverter/jodconverter-online -->
  13. <dependency>
  14. <groupId>org.jodconverter</groupId>
  15. <artifactId>jodconverter-online</artifactId>
  16. <version>4.2.2</version>
  17. </dependency>

yml

  1. jodconverter:
  2. online:
  3. enabled: true
  4. url: http://10.1.20.58:9980

代码

  1. @Autowired
  2. private DocumentConverter documentConverter;
  3. @GetMapping("test")
  4. public void test(HttpServletResponse response) throws Exception {
  5. File file = new File("D:\\Download/123.docx");
  6. File outputFile = new File("D:\\Download/document.pdf");
  7. documentConverter.convert(file).to(outputFile).execute();
  8. }

local

<dependency>
    <groupId>org.jodconverter</groupId>
    <artifactId>jodconverter-core</artifactId>
    <version>4.2.2</version>
</dependency>

<!--springboot支持包,里面包括了自动配置类 -->
<dependency>
    <groupId>org.jodconverter</groupId>
    <artifactId>jodconverter-spring-boot-starter</artifactId>
    <version>4.2.2</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.jodconverter/jodconverter-online -->
<dependency>
    <groupId>org.jodconverter</groupId>
    <artifactId>jodconverter-local</artifactId>
    <version>4.2.2</version>
</dependency>

nacos

jodconverter:
  local:
    enabled: true
    max-tasks-per-process: 10
    port-numbers: 8110
    office-home: C:\Program Files (x86)\OpenOffice 4
    #office-home: /opt/openoffice4

使用同上

@Autowired
private DocumentConverter documentConverter;

@GetMapping("test")
public void test(HttpServletResponse response) throws Exception {
  File file = new File("D:\\Download/123.docx");
  File outputFile = new File("D:\\Download/document.pdf");
  documentConverter.convert(file).to(outputFile).execute();
}