LibreOffice preview configuration

P4 Code Review uses LibreOffice to generate browser previews for supported office documents. LibreOffice converts supported documents to PDF, allowing users to preview content without downloading the original file.

To enable document previews, install LibreOffice on the P4 Code Review host and ensure that the LibreOffice executable is available to P4 Code Review.

Supported document formats

P4 Code Review can generate previews for the following document formats:

  • Microsoft Word: DOC, DOCX, DOTX

  • Microsoft Excel: XLS, XLSX

  • Microsoft PowerPoint: PPT, PPTX

  • OpenDocument: ODT

  • Rich Text Format: RTF

  • Microsoft Visio: VSD, VSDX

  • Apple iWork: KEY, NUMBERS, PAGES

Configure LibreOffice document previews

LibreOffice preview settings are configured in the SWARM_ROOT/data/config.php file:

'libreoffice' => array(
    'path'          => 'soffice',  // LibreOffice executable.
    'timeout'       => 120,        // Preview conversion timeout (seconds, 0 disables).
    'content_check' => true,       // Validate file content before preview generation.
),

Configuration options

Parameter

Default

Description Type

path

soffice

Path to the LibreOffice executable used to generate previews.

String

timeout

120

Specifies the maximum number of seconds allowed for document preview generation.

If the conversion exceeds the configured time limit, the preview fails and is reported as unavailable.

Set the value to 0 to disable timeout enforcement.

Integer

content_check

true

Validates a file's contents before sending it to LibreOffice for conversion.

When enabled, P4 Code Review verifies that the file contains supported office document content. Files whose contents do not match a supported office document format are rejected and are not previewed.

Boolean

Document preview security

To improve the security and reliability of document preview generation, P4 Code Review includes the following protections:

  • Content validation before preview generation.

  • Configurable conversion time limits.

  • LibreOffice macros are disabled during conversion.

  • Automatic updates of external document links are disabled during conversion.

These protections help ensure that document preview generation remains isolated and that problematic documents result in a controlled preview failure rather than affecting other P4 Code Review operations.

Preview unavailable

A document preview might not be available for the following reasons:

Unsupported content

P4 Code Review validates document contents before generating a preview.

For example:

  • A PDF file renamed with a .docx extension.

  • An image file renamed with a .xlsx extension.

  • Any file whose contents are not recognized as a supported office document format.

When content validation fails, the preview is unavailable and the original file remains available for download.

Conversion timeout

If document conversion exceeds the configured timeout value, preview generation is stopped and the preview is reported as unavailable.

The original document remains available for download.

Notes for administrators

  • Existing document previews remain cached after an upgrade.

  • Content validation applies only when a preview is generated or regenerated.

  • To apply updated validation rules to previously generated previews, clear the LibreOffice preview cache and regenerate the preview.

  • Disabling content_check restores the previous behavior and allows files to be passed to LibreOffice based on file extension alone.