Backend Development 4 min read

SpringBoot + OpenOffice File Conversion Service: Upload, Convert, and Preview Documents

This article introduces a SpringBoot-based service that leverages OpenOffice to upload, convert (DOC/DOCX/XLS/PPT to PDF or HTML), and preview files directly in the browser, detailing built‑in features, configuration settings, and sample controller code for seamless integration.

Java Architect Essentials
Java Architect Essentials
Java Architect Essentials
SpringBoot + OpenOffice File Conversion Service: Upload, Convert, and Preview Documents

The project provides a SpringBoot service built on OpenOffice that converts office files (DOC, DOCX, XLS, PPT) into PDF or HTML formats and renders them directly in a browser.

Overview

Based on the OpenOffice service, the application supports file upload, conversion, local preview, and remote preview functionalities.

Built‑in Features

File upload

File conversion

File preview

Remote file preview

Code Integration

Configuration in application.properties to enable the JODConverter local mode and specify OpenOffice ports:

# Disabled by default; set to true to enable
jodconverter.local.enabled=true
# Enable multiple OpenOffice processes, each port corresponds to a process
jodconverter.local.portNumbers=8100,8200
# Maximum tasks per OpenOffice process before restart
jodconverter.local.maxTasksPerProcess=100

The application automatically starts two conversion processes. Below is a sample controller that handles file upload and performs real‑time conversion to PDF and HTML:

@RestController
@RequestMapping("document")
public class ConverterController {

    @Autowired
    private DocumentConverter documentConverter;

    /**
     * File upload
     */
    @RequestMapping("/upload")
    public Result upload(MultipartFile file) {
        try {
            if (file != null) {
                File parentFile = createParentFile();
                String fileName = file.getOriginalFilename();
                String suffix = fileName.substring(fileName.lastIndexOf("."));
                String uuid = IdUtil.simpleUUID();
                fileName = uuid + suffix;
                File docFile = new File(parentFile, fileName);
                FileUtil.writeFromStream(file.getInputStream(), docFile);
                // Date directory
                String fileDay = DateUtil.thisYear() + "/" + (DateUtil.thisMonth() + 1) + "/" + DateUtil.thisDayOfMonth();
                String imagePath = SystemConstant.FILE + "/document/" + fileDay + "/" + fileName;
                // Real‑time conversion
                logger.info("Starting PDF conversion...");
                File toFile = new File(parentFile, uuid + ".pdf");
                documentConverter.convert(docFile).to(toFile).execute();
                logger.info("Starting HTML conversion...");
                toFile = new File(parentFile, uuid + ".html");
                converter(docFile, toFile);
                return Result.ok(imagePath);
            } else {
                return Result.error();
            }
        } catch (Exception e) {
            logger.error("Conversion exception {}", e);
            return Result.error();
        }
    }
}

Conclusion

Many older articles on Java integration with OpenOffice suffer from Linux startup issues; this example only requires the OpenOffice service to be installed, and the application will automatically spawn the necessary processes.

Project Links

Source code and additional resources can be obtained by replying "Online" to the associated public account.

backendJavaSpringBootDocumentProcessingFileConversionOpenOffice
Java Architect Essentials
Written by

Java Architect Essentials

Committed to sharing quality articles and tutorials to help Java programmers progress from junior to mid-level to senior architect. We curate high-quality learning resources, interview questions, videos, and projects from across the internet to help you systematically improve your Java architecture skills. Follow and reply '1024' to get Java programming resources. Learn together, grow together.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.