Skip to content

Installation

Requirements

  • Drupal ^11.2 or ^12.
  • PHP 8.3 or later.
  • The core modules File, Text and Editor. The module declares them, so Drupal enables them with it. On a site updated from 2.0.x the update installs Editor if it is missing.
  • LibreOffice, with the Writer component for DOC, DOCX, ODT and RTF, and the Impress component for PPTX. The tests run with LibreOffice 7.4 and 25.2.
  • The PHP function proc_open, not disabled in disable_functions.
  • On Drupal 12, the contrib module drupal/text_with_summary if a field has a summary. See below.

See Versions for the older branches. 2.0.x is the line for Drupal 10, 11.0 and 11.1. If you come from 2.0.x, read Upgrading.

Install the module with Composer and enable it:

composer require drupal/doc_to_html
drush en doc_to_html
drush cr

Drupal 12 and fields with a summary

Drupal 12 moved the summary widget of text_with_summary fields out of core. If a field has a summary, as the Body of an Article does, install the contrib module:

composer require drupal/text_with_summary
drush en text_with_summary

The DOC to HTML widget uses the summary widget that is registered, whoever provides it. A text_long field needs nothing.

Install LibreOffice on the machine where PHP runs. A LibreOffice on your laptop does not help if Drupal runs in a container or on a server.

The cost of LibreOffice

LibreOffice adds several hundred megabytes to an image or a server, and it must be kept up to date with the rest of your system. The nogui packages below are the smallest option on Debian and Ubuntu. If you cannot install software on your hosting, see the comparison.

Debian and Ubuntu

sudo apt-get update
sudo apt-get install -y libreoffice-writer-nogui libreoffice-impress-nogui

libreoffice-writer-nogui converts DOC, DOCX, ODT and RTF. libreoffice-impress-nogui converts PPTX. If you only enable word processing formats, the Writer package is enough.

Docker image

Add the packages to the image that runs PHP:

RUN apt-get update \
    && apt-get install -y --no-install-recommends \
        libreoffice-writer-nogui \
        libreoffice-impress-nogui \
    && rm -rf /var/lib/apt/lists/*

The module gives each conversion its own LibreOffice profile and home folder, so the web server user does not need a home directory. See How the data flows.

DDEV

Add the packages to .ddev/config.yaml and restart:

webimage_extra_packages:
  - libreoffice-writer-nogui
  - libreoffice-impress-nogui
ddev restart

macOS

Install the application and point the module to it:

brew install --cask libreoffice

On macOS the default base path is /Applications/LibreOffice.app/Contents/MacOS and the command is soffice. The module sets these defaults at install time.

Verify the installation

drush dth:version

The command prints the LibreOffice version. If it fails, check the base path and command on the LibreOffice Settings page, see Configuration. The status report also has a DOC to HTML entry.

The DOC to HTML entries in the Drupal status report.

Next step

Continue with Getting started.