mrcnpdlk / unoconv-api
Unoconv API
Installs: 28 176
Dependents: 0
Suggesters: 0
Security: 0
Stars: 6
Watchers: 1
Forks: 1
Open Issues: 0
Requires
- php: >=7.2
- ext-curl: *
- ext-json: *
- mikehaertl/php-shellcommand: ^1
- mrcnpdlk/lib-configuration: ^0
- mrcnpdlk/lib-exception: ^0
- myclabs/php-enum: ^1
- psr/log: ^1
Requires (Dev)
Suggests
- monolog/monolog: Allows more advanced logging of the application flow
README
Unoconv API
This API is object oriented PHP overlay for unoconv
binary.
Installation
Install unoconv
and required libraries
sudo apt-get install unoconv
Install the latest version with composer
composer require mrcnpdlk/unoconv-api
Basic usage
<?php use Monolog\Handler\ErrorLogHandler; use Psr\Log\LogLevel; require __DIR__ . '/../vendor/autoload.php'; // Logger instance $logger = new \Monolog\Logger('unoconv-api'); $logger->pushHandler(new ErrorLogHandler(ErrorLogHandler::OPERATING_SYSTEM, LogLevel::DEBUG)); // Set default value for handler $oConfig = new \Mrcnpdlk\Api\Unoconv\Config([ 'binary' => '/usr/bin/unoconv', 'logger' => $logger, 'timeout'=> 300 ]); $oApi = new \Mrcnpdlk\Api\Unoconv\Api($oConfig);
Config option
Detailed documentation you can find here.
Create document
$res = $oApi->transcode($sourceFile, $format, $destination, $exportOpts); var_dump($res);
Parameters transcode
method:
Example:
$oApi = new \Mrcnpdlk\Api\Unoconv\Api($oConfig); $from = __DIR__ . '/../devel/test.docx'; $res = $oApi->transcode($from, null, __DIR__, [ ExportType::PageRange => '1-1', // page range (string) ExportType::Watermark => 'FOO bar BAZ', // watermark text (string) ExportType::Printing => 0, // printing permission (int) ExportType::RestrictPermissions => true, // restrict permission (bool) ExportType::PermissionPassword => 'password1', ExportType::EnableCopyingOfContent => false, // copy permission (bool) ExportType::Changes => 0, // changes permission (int) ExportType::DocumentOpenPassword => 'password2', // password to open file (string) ]); var_dump($res);
Webservice
Api supports dockerized unoconv webservice for generating simple PDF file.
To start container writedocker-compose.yml
and just docker-compose up -d
version: "3.7"
services:
app:
image: zrrrzzt/docker-unoconv-webservice:10.14.0
ports:
- 3000:3000
environment:
- PAYLOAD_MAX_SIZE=5242880
restart: unless-stopped
$res = $oApi->wsGetPdf($sourceFile, $destination); var_dump($res);
License
Released under the MIT license