lukaswhite / document-converter
Installs: 5 165
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires (Dev)
- phpunit/php-code-coverage: ^9.2
- phpunit/phpunit: ^9.5
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