Laravel wrapper to interact with UnoServer, which allows you to convert documents using LibreOffice.

dev-master 2023-09-29 07:18 UTC

This package is auto-updated.

Last update: 2024-03-29 08:16:24 UTC


Latest Version on Packagist Total Downloads

This package is a Laravel-specific wrapper around unoserver commands, these let you easily convert office documents, like you would in LibreOffice.

Helper commands are provided to get you set up quickly.


Install the package in your project:

composer require happydemon/unoserver && \

Vendor publish

You can run vendor:publish --tag=unoserver te publish the config file and the platform installers.

You can also be more specific in what you want to publish:

  • vendor:publish --tag=unoserver.config
  • vendor:publish --tag=unoserver.platforms

Set up

To get started quickly we bundled install scripts, these got exported thanks to vendor:publish.

From your application's root directory you can run:

sh platforms/mac
sh platforms/ubuntu

For Mac it's important homebrew is installed, for Ubuntu python3

The script will install LibreOffice, unoserver & set up some .env variables.



vendor:publish published the unoserver.php config file.

If you're making use of the generated unoserver command to start a server, you'll need to define the path to your local libreoffice esecutable.

# For mac usually: /Applications/LibreOffice.app/Contents/MacOS/soffice

You should always provide the path to a python executable that supports unoserver:

# For mac usually: /Applications/LibreOffice.app/Contents/Resources/python

Important: both UNSORSERVER_EXEC_LIBRE and UNSORSERVER_EXEC_PYTHON environment variables get configured automatically when you set up your environment with a set-up script.



This command generates bash scripts to:

  • start a unoserver
  • send convert requests to that server


It takes a servername as the only argument (this would be a server you defined in the unoserver.servers.* config), if not provided it will use the default server.


--ip= IP the unoserver is hosted on (defaults to
--port= Port the uno server is running on (defaults to 2002)
--unoserver Generate unoserver in the app's bin folder
--unoconvert Generate unoconvert in the app's bin folder
php artisan make:unoserver-cmd

This will generate 2 files in base_path('bin'):

  • unoserver: lets you quickly start up a unoserver instance
  • unoconvert: lets you correctly interact with a unoserver instance

If a server was defined as an argument, both files' name will be suffixed with that server name.

Always make sure there is a bin/unoserver running when developing locally.


The HappyDemon\UnoServer\Facades\UnoServer facade can be used to connect to a server and send it documents to convert for us.


Connections are defined under the unoserver.servers config.

There are 2 types configuration;


You can define the path to a bash script.

You can check the output from php artisan unoserver:helpers -h as an example for a command file.


return [
    'servers' => [
        'script' => [
            'command' => '~/www/bin/unoconvert',


You can also define the server connection manually.


return [
    'servers' => [
        'remote' => [
            // IP where the unoserver is running
            'interface' => '',
            'port' => 2002,


In order to convert we'll have to define which server we'll be connecting to and the local file path to the source file.

You can convert either documents or spreadsheets:

use HappyDemon\UnoServer\Facades\UnoServer;

// Use the UnoServerFactory to create a Unoserver
$document = app(\HappyDemon\UnoServer\UnoServerFactory::class)

// Use the UnoServer facade to create a UnoServer
$document = UnoServer::connect('script')

// Delete the source file after a successful conversion:   
$spreadsheet = UnoServer::connect('remote')
    ->fromSpreadsheet(storage_path('mySheets.xlsx', true))

The next step is defining which format we'll be converting to and executing the call:

$generatedFile = $document->toFormat('pdf')

The convert() call returns a Illuminate\Http\UploadedFile object, which offers several options to store your file on any file system disk:

$generatedFile->store('documents/rendered', ['disk' => 'public']);
$generatedFile->storePublicly('documents/rendered', ['disk' => 'public']);

$generatedFile->storeAs('documents/rendered','yourWordDoc.pdf', ['disk' => 'public']);
$generatedFile->storePubliclyAs('documents/rendered','yourWordDoc.pdf', ['disk' => 'public']);

IOC bindings

Class function
\HappyDemon\UnoServer\UnoServerFactory Configures a UnoServer with a proper connection.
\HappyDemon\UnoServer\UnoServer Object used to configure & convert documents & spreadsheets.

Change log

Please see the changelog for more information on what has changed recently.


$ composer test


Please see contributing.md for details and a todolist.


If you discover any security related issues, please email maxim.kerstens@gmail.com instead of using the issue tracker.



MIT. Please see the license file for more information.