codeinc / unoconv-webservice-client
Unoconv webservice PHP客户端
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-08-29 04:57:45 UTC
README
这个PHP 7库是zrrrzzt/tfk-api-unoconv的一个简单客户端,特别是其Docker实现。该库完全兼容PSR-7,并使用Guzzle作为其HTTP客户端。
使用方法
<?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');
将本地文件转换为并显示结果
<?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;
将本地文件转换为另一个本地文件
<?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);
安装
此库可通过Packagist获得,并可以使用Composer进行安装
composer require codeinc/unoconv-webservice-client
许可
该库以MIT许可证发布(见LICENSE
文件)。