How to use LibreOffice to convert document formats under CentOS

How to use LibreOffice to convert document formats under CentOS

Project requirements require some preprocessing of uploaded documents. If the user uploads a document in doc format, it needs to be processed into docx or pdf format so that the subsequent process can extract the document content.

I first tried the phpoffice/phpword package and found that its conversion of doc was not ideal. This package is more suitable for generating documents based on content rather than converting documents, which is not very suitable for my needs.

Then I discovered the open source tool LibreOffice. After using it, I found it to be very effective, so I’d like to share it with you.

The server is CentOS7. Use yum to install LibreOffice directly. It takes about 600MB+ of disk space:

# You can delete it before installing it to prevent it from being installed before. yum remove libreoffice-*
yum install libreoffice

After waiting for the installation to complete, confirm the version. Although the official version is 6.1, the yum package is still 5.3.6, but there is no problem in using it. Here I still recommend that you use your own Linux system package management tool to install it, which can save a lot of trouble.

[root@localhost /]# soffice --version
LibreOffice 5.3.6.1 30 (Build: 1)

If you don't know how to use it, you can use soffice --help to see the help. There are many parameters and usage cases. The format conversion is very simple:

soffice --headless --convert-to docx /opt/upload/source/123.doc --outdir /opt/upload/source

The above command converts the /opt/upload/source/123.doc file into docx format and outputs it to the / opt/upload/source folder.

By default:

  1. The output file will be saved with the source file name + new extension;
  2. It will overwrite the existing file with the same name in outdir;

A successful conversion will output something like this:

convert /opt/upload/source/123.doc -> /opt/upload/source/123.docx using filter : MS Word 2007 XML
Overwriting: /opt/upload/source/123.docx

LibreOffice will automatically match the format filter according to the file format. As for which formats it supports, you can refer to the official website.

Summarize

The above is the editor's introduction to the method of using LibreOffice under CentOS to achieve document format conversion. I hope it will be helpful to everyone. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!
If you find this article helpful, please feel free to reprint it and please indicate the source. Thank you!

You may also be interested in:
  • Demonstration of building ElasticSearch middleware and common interfaces under centos7 in Linux system
  • Summary of common commands for building ZooKeeper3.4 middleware under centos7

<<:  mysql8.0 windows x64 zip package installation and configuration tutorial

>>:  How to implement parent-child component communication with Vue

Recommend

A time-consuming troubleshooting process record of a docker error

Table of contents origin Environmental Informatio...

How to generate Hive table creation statement comment script in MySQL metadata

Preface This article mainly introduces the releva...

Login interface implemented by html+css3

Achieve results First use HTML to build a basic f...

Solution to the problem "Table mysql.plugin doesn't exist" when deploying MySQL

Today I deployed the free-installation version of...

RHCE installs Apache and accesses IP with a browser

1. at is configured to write "This is a at t...

Example of how to increase swap in CentOS7 system

Preface Swap is a special file (or partition) loc...

Implementing access control and connection restriction based on Nginx

Preface Nginx 's built-in module supports lim...

18 killer JavaScript one-liners

Preface JavaScript continues to grow and prosper ...

Vue calculated property implementation transcript

This article shares the Vue calculation property ...

Example analysis of the page splitting principle of MySQL clustered index

This article uses an example to illustrate the pa...