[JAVA] I tried using OnlineConverter with SpringBoot + JODConverter

Overview

A memo when using jodConverter with OnlineConverter. Since SpringBoot was used, it is implemented using JODConverter Spring Boot Starter.

environment

OnlineConverter caller implementation

application.yml


jodconverter:
  online:
    enabled: true
    url:[URL of Online Converter server]

OnlineConverter server implementation

application.yml


jodconverter:
  enabled: true
  officeHome:[LibreOffice installation destination]
@RestController
public class SampleController {
  @Autowired
  private DocumentConverter documentConverter;

  @RequestMapping(path = "/api/jodconverter/lool/convert-to/{outputExtension}", method = RequestMethod.POST)
  public Resource convert(
      @RequestParam("data") MultipartFile file,
      @PathVariable("outputExtension") String outputExtension
  ) throws IOException, OfficeException {
    //Get file information before conversion
    String inputExtension = FilenameUtils.getExtension(file.getOriginalFilename());
    DocumentFormatRegistry registry = this.documentConverter.getFormatRegistry();
    DocumentFormat inputFormat = registry.getFormatByExtension(inputExtension);
    if (inputFormat == null) {
      inputFormat = registry.getFormatByExtension("xlsx");
    }

    //Post-conversion extension setting
    DocumentFormat outputFormat = registry.getFormatByExtension(outputExtension);

    //Conversion process
    try (
        InputStream is = file.getInputStream();
        ByteArrayOutputStream os = new ByteArrayOutputStream();
    ) {
      this.documentConverter.convert(is).as(inputFormat).to(os).as(outputFormat).execute();
      return new ByteArrayResource(os.toByteArray());
    } catch (Exception e) {
      e.printStackTrace();
    }
    return null;
  }
}

Summary

I haven't had a chance to use OnlineConverter before, so I learned how to use it.

However, LocalConverter is easier to install because there is no server implementation when using OnlineConverter. I wonder if I will use it unless there is a good reason. .. ..

Recommended Posts

I tried using OnlineConverter with SpringBoot + JODConverter
I tried using JOOQ with Gradle
I tried using Realm with Swift UI
I tried using Scalar DL with Docker
I tried using OpenCV with Java + Tomcat
I tried using Gson
I tried using TestNG
I tried using Galasa
I made blackjack with Ruby (I tried using minitest)
I tried DI with Ruby
I tried using azure cloud-init
I tried using Apache Wicket
I tried using Java REPL
I tried UPSERT with PostgreSQL.
I tried BIND with Docker
I tried to get started with Swagger using Spring Boot
I tried using the CameraX library with Android Java Fragment
I tried using anakia + Jing now
I tried Angular tutorial + SpringBoot + PostgreSQL
I tried using Spring + Mybatis + DbUnit
I tried morphological analysis with MeCab
I tried to interact with Java
I tried using Java8 Stream API
I tried using JWT in Java
I tried GraphQL with Spring Boot
[Android] I tried using Coordinator Layout.
I tried Flyway with Spring Boot
I tried using Pari gp container
I tried using WebAssembly Stadio (2018/4/17 version)
I tried customizing slim with Scaffold
I tried using Java memo LocalDate
I tried using GoogleHttpClient of Java
I tried connecting to MySQL using JDBC Template with Spring MVC
I tried using Elasticsearch API in Java
I tried using Java's diagnostic tool Arthas
I tried using UICollectionViewListCell added from Xcode12.
I tried to get started with WebAssembly
I tried time-saving management learning with Studyplus.
It's new, but I tried using Groonga
I tried playing with BottomNavigationView a little ①
I tried Lazy Initialization with Spring Boot 2.2.0
Using SSIServlet with built-in Tomcat of SpringBoot 2.2.4
I tried to implement ModanShogi with Kinx
01. I tried to build an environment with SpringBoot + IntelliJ + MySQL (MyBatis) (Windows10)
I tried using Junit on Mac VScode Maven
[For beginners] I tried using DBUnit in Eclipse
I tried barcode scanning using Rails + React + QuaggaJS
I tried to verify AdoptOpenJDK 11 (11.0.2) with Docker image
I tried to make Basic authentication with Java
I tried to manage struts configuration with Coggle
[For beginners] I tried using JUnit 5 in Eclipse
I tried to manage login information with JMX
I tried writing CRUD with Rails + Vue + devise_token_auth
[Android] I quit SQLite and tried using Realm
[Java] I tried to connect using a connection pool with Servlet (tomcat) & MySQL & Java
I tried Spring.
[API] I tried using the zip code search API
I tried tomcat
I tried Eclipse MicroProfile OpenAPI with WildFly Swarm
I tried youtubeDataApi.
I tried refactoring ①