jodconverter4.1.0版本改进解析

jodconverter 4.1.0版本的话,改进了api的结构,同时新增了local以及online的模块,本文就来分析一下。php

maven

<dependency>
            <groupId>org.jodconverter</groupId>
            <artifactId>jodconverter-spring-boot-starter</artifactId>
            <version>4.1.0</version>
        </dependency>

依赖变化

新版的话,对原来的jodconverter-core进行了抽离,将对libreoffice相关jar包的依赖从core模块中抽取出来,抽到jodconverter-local模块当中。
另外也新增了jodconverter-online模块,以支持libreoffice online server的远程调用。html

  • Uno
    local方式是本地启动libreoffice,而后使用uno进行编程,操做本地的office。

Uno-Arc

相关的jar依赖以下git

<dependency>
    <groupId>org.libreoffice</groupId>
    <artifactId>juh</artifactId>
    <version>5.4.2</version>
</dependency>
<dependency>
    <groupId>org.libreoffice</groupId>
    <artifactId>jurt</artifactId>
    <version>5.4.2</version>
</dependency>
<dependency>
    <groupId>org.libreoffice</groupId>
    <artifactId>ridl</artifactId>
    <version>5.4.2</version>
</dependency>
<dependency>
    <groupId>org.libreoffice</groupId>
    <artifactId>unoil</artifactId>
    <version>5.4.2</version>
</dependency>
  • online

This is LibreOffice Online, which provides basic collaborative editing of documents in a browser by re-using the LibreOffice core. Rendering fidelity should be excellent, and interoperability match that of LibreOffice.
能够部署到本身的私有云端,而后经过有ui界面能够操做,也经过http对外提供api服务。github

好比spring

- API: HTTP POST to /lool/convert-to/<format>
        - the format is e.g. "png", "pdf" or "txt"
        - the file itself in the payload
    - example
        - curl -F "data=@test.txt" https://localhost:9980/lool/convert-to/docx > out.docx
    - or in html:
          <form action="https://localhost:9980/lool/convert-to/docx" enctype="multipart/form-data" method="post">
              File: <input type="file" name="data"><br/>
              <input type="submit" value="Convert to DOCX">
          </form>

jodconverter-online模块基于这个api使用apache http client进行了client端的封装并进行链接池的优化处理。docker

api变化

4.1.0版本改进了api,方便进行流式操做
旧版的以下apache

jodConverter.convert(inputFile, outputFile);

新版以下编程

File inputFile = new File("spreadsheet.xls");
File outputFile = new File("spreadsheet.ods");
JodConverter
         .convert(inputFile)
         .to(outputFile)
         .execute();

或者api

InputStream inputStream = ...
OutputStream outputStream = ...
JodConverter
         .convert(inputStream)
         .as(DefaultDocumentFormatRegistry.XLS)
         .to(outputStream)
         .as(DefaultDocumentFormatRegistry.ODS)
         .execute();

doc

相关文章
相关标签/搜索