codeinc / unoconv-webservice-client
Unoconv webservice PHP client
1.0.0
2019-02-28 21:08 UTC
Requires
- php: >=7.2
- ext-json: *
- guzzlehttp/guzzle: ^6.3
- psr/http-message: ^1.0
This package is auto-updated.
Last update: 2024-10-29 05:40:38 UTC
README
This PHP 7 library is a (very) simple client for zrrrzzt/tfk-api-unoconv and in particular its Docker implementation. The library is fully PSR-7 compatible and uses Guzzle as its HTTP client.
Usage
<?php use CodeInc\UnoconvClient\UnoconvClient; $client = new UnoconvClient('http://localhost:3000'); // lists supported formats (calls /unoconv/formats) $client->getFormats(); // list supported format for the graphics type (calls /unoconv/formats/graphics) $client->getFormats('graphics'); // returns the API server's uptime (calls /healthz) $client->getHealth(); // returns all versions of installed dependencies lookup (calls /unoconv/versions) $client->getVersions(); // converts a document $responseStream = $client->convert($sourceStream, 'pdf');
To convert a local file and display the result
<?php use CodeInc\UnoconvClient\UnoconvClient; use GuzzleHttp\Psr7\LazyOpenStream; $client = new UnoconvClient('http://localhost:3000'); $localFilePath = '/path/to/my/document.docx'; $localFileStream = new LazyOpenStream($localFilePath, 'r'); $responseStream = $client->convert($localFileStream, 'pdf'); header('Content-Type: application/pdf'); echo $responseStream;
To convert a local file to another local file
<?php use CodeInc\UnoconvClient\UnoconvClient; use GuzzleHttp\Psr7\LazyOpenStream; use function GuzzleHttp\Psr7\copy_to_stream; $client = new UnoconvClient('http://localhost:3000'); $localFilePath = '/path/to/my/document.docx'; $localFileStream = new LazyOpenStream($localFilePath, 'r'); $responseStream = $client->convert($localFileStream, 'pdf'); $pdfFilePath = '/path/to/my/document.pdf'; $pdfFileStream = new LazyOpenStream($pdfFilePath, 'w'); copy_to_stream($responseStream, $pdfFileStream);
Installation
This library is available through Packagist and can be installed using Composer:
composer require codeinc/unoconv-webservice-client
License
The library is published under the MIT license (see LICENSE
file).