mrcnpdlk/unoconv-api

0.7.1 2019-03-03 00:00 UTC

This package is auto-updated.

Last update: 2024-12-16 22:23:31 UTC


README

Latest Stable Version Latest Unstable Version Total Downloads Monthly Downloads License

Scrutinizer Code Quality Build Status Code Coverage

Code Climate Issue Count

Build Status

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