lukaswhite/document-converter

0.0.1 2022-07-28 14:15 UTC

This package is auto-updated.

Last update: 2024-02-28 17:29:32 UTC


README

A PHP wrapper around Libreoffice for converting documents from one format to another.

For example:

  • Microsoft Word to PDF
  • OpenOffice to Microsoft Word
  • PDF to HTML
  • ...and many more

Installation

IMPORTANT: You must have Libreoffice installed.

Using composer:

composer require lukaswhite/document-converter

Usage

use Lukaswhite\DocumentConverter\Converter;

$converter = new Converter('/path/to/document.doc');
$converter->toPDF();

All being well, this should create a file named document.pdf in the same folder.

To customize the filename:

$converter->outputAs('converted')->toPDF();

...or the output path:

$converter->outputTo('/path/to/converted/files')->toPDF();

You can of course combine these:

$converter->outputAs('converted')
    ->outputTo('/path/to/converted/files')
    ->toPDF();

For other formats:

$converter->toFormat('doc');

Return Format

The conversion method returns an object that contains information about the conversion:

$result = $converter->toPDF();

$result->getFilepath(); // e.g. /path/to/document.pdf
$result->getFilename(); // e.g. document.pdf
$result->getExtension(); // e.g. pdf