jodconverter 4.1.0版本的話,改進了api的結構,同時新增了local以及online的模塊,本文就來分析一下。php
<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
相關的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>
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
- 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端的封裝並進行鏈接池的優化處理。spring
4.1.0版本改進了api,方便進行流式操做 舊版的以下docker
jodConverter.convert(inputFile, outputFile);
新版以下apache
File inputFile = new File("spreadsheet.xls"); File outputFile = new File("spreadsheet.ods"); JodConverter .convert(inputFile) .to(outputFile) .execute();
或者編程
InputStream inputStream = ... OutputStream outputStream = ... JodConverter .convert(inputStream) .as(DefaultDocumentFormatRegistry.XLS) .to(outputStream) .as(DefaultDocumentFormatRegistry.ODS) .execute();