Giter Club home page Giter Club logo

unoconv-api's Introduction

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

Property Default value Type Description
binary /usr/bin/unoconv string executable unoconv library
host localhost string Host where libreoffice server is listen
port 2002 int Port where libreoffice server is listen
docType DocType::DOCUMENT() DocType Document type
format FormatType::PDF() FormatType Output format
timeout 60 int Connection timeout
options urp;StarOffice.ComponentContext string Connection option
logger NullLogger instance LoggerInterface Logger
webservice http://localhost:3000 string External WebService url, see

Detailed documentation you can find here.

Create document

$res     = $oApi->transcode($sourceFile, $format, $destination, $exportOpts);
var_dump($res);

Parameters transcode method:

Parameter Type Description
sourceFile string Valid path of input file. Otherwise InvalidFileArgumentException is thrown.
format FormatType|NULL If NULL default value form Config object is taken.
destination string|NULL If NULL directory of input file and default extension for Format is taken. If sourceFile is valid directory path then output file is saved into this directory.
exportOpts array Array of export options. See the list

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

unoconv-api's People

Contributors

mrcnpdlk avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.