PHP Unoconv - An Object Oriented library which allow easy to use file conversion with Unoconv.

Overview

PHP Unoconv

Build Status

An Object Oriented library which allow easy to use file conversion with Unoconv.

Install

The recommended way to install PHP-Unoconv is through composer.

{
    "require": {
        "php-unoconv/php-unoconv": "~0.2"
    }
}

Documentation

Documentation available at http://php-unoconv.readthedocs.org/

API Usage

To instantiate Unoconv driver, the easiest way is :

$unoconv = Unoconv\Unoconv::create();

You can customize your driver by passing a Psr\Log\LoggerInterface or configuration options.

Available options are :

  • timeout : the timeout for the underlying process.
  • unoconv.binaries : the path (or an array of paths) for a custom binary.
$unoconv = Unoconv\Unoconv::create(array(
    'timeout'          => 42,
    'unoconv.binaries' => '/opt/local/unoconv/bin/unoconv',
), $logger);

To transcode a file, use the transcode method. For the complete format list supported by unoconv, refer to the unoconv CLI.

$unoconv->transcode('document.docx', 'pdf', 'document.pdf');

You can optionaly transcode a given page range using the fourth argument :

// pages 1 to 14
$unoconv->transcode('document.docx', 'pdf', 'document.pdf', '1-14');

Silex Service Provider

A Silex Service Provider is available, all parameters are optionals :

$app = new Silex\Application();
$app->register(new Unoconv\UnoconvServiceProvider(), array(
    'unoconv.configuration' => array(
        'unoconv.binaries' => '/opt/local/unoconv/bin/unoconv',
        'timeout'          => 42,
    ),
    'unoconv.logger'  => $app->share(function () {
        return $app['monolog']; // use Monolog service provider
    }),
));

License

Released under the MIT license

Bitdeli Badge

Comments
  • is there a way to use this as a vendor in my cakephp?

    is there a way to use this as a vendor in my cakephp?

    Hi there,

    I am having some problems using exec to call the unoconv. Even though I have no problems running it as www-data in my terminal.

    So I am interested to implement your library.

    Can you give some documentations as to how to use this in a cakephp app? Or even a pure php script?

    Thank you.

    opened by simkimsia 22
  • Problema al convertir DOCX a PDF:

    Problema al convertir DOCX a PDF: "Unoconv failed to transcode file"

    Un cordial saludo primero que todo.

    Bueno la cuestión es la siguiente y es que me esta saliendo un mensaje "Unoconv failed to transcode file" al intentar convertir el documento a PDF, ya tengo instalado Unoconv en Symfony:

    Proyecto ------ app ------ bin ------ src ------ vendor |____ php-unoconv ------ web

    Y pues lo estoy utilizando junto con otra librería llama PHPWord que me crea documentos DOCX entonces lo que realizo es lo siguiente:

    use Unoconv\Unoconv; use Symfony\Component\Process\ExecutableFinder;

    class ReportController extends DocumentController { ......... public function testDocsToPdfAction() { $phpWord = new \PhpOffice\PhpWord\PhpWord(); ....... $objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007'); $objWriter->save('HelloWorld.docx');

     $dest = '/var/www/html/project/web/HelloWorld.pdf';
     $unoconv = Unoconv::create();
     $unoconv->transcode('/var/www/html/project/web/HelloWorld.docx', 'pdf', $dest);
     $this->assertTrue(file_exists($dest));
     unlink($dest);
     }
    

    }

    Para si alguien me puede ayudar que puede estar ocurriendo, de verdad se lo agradecería.

    opened by deivisaherreraj 2
  • Unable to run on a different port

    Unable to run on a different port

    Hi,

    I'm having an issue with unoconv where it is unable to start the service because the default port 2002 is already in use by another process.

    From what I can see, there is no way to setup a different port.

    I'm using https://github.com/alchemy-fr/Media-Alchemyst

    opened by xorti 1
  • Bump phpunit/phpunit from 3.7.21 to 4.8.28

    Bump phpunit/phpunit from 3.7.21 to 4.8.28

    Bumps phpunit/phpunit from 3.7.21 to 4.8.28.

    Changelog

    Sourced from phpunit/phpunit's changelog.

    [4.8.28] - 2016-11-14

    Fixed

    • Improved the fix for #1955: Process isolation fails when running tests with phpdbg -qrr

    [4.8.27] - 2016-07-21

    Fixed

    • Fixed #1968: Invalid data sets are not handled correctly for @testWith annotation

    [4.8.26] - 2016-05-17

    Fixed

    [4.8.25] - 2016-05-10

    Fixed

    • Fixed #2112: Output is html entity encoded when ran through phpdbg
    • Fixed #2158: Failure to run tests in separate processes if a file included into main process contains constant definition

    [4.8.24] - 2016-03-14

    Fixed

    • Fixed #1959: Prophecy errors are not handled correctly
    • Fixed #2039: TestDox does not handle snake_case test methods properly
    • Fixed #2109: Process isolation leaks global variable

    [4.8.23] - 2016-02-11

    Fixed

    • Fixed #2072: Paths in XML configuration file were not handled correctly when they have whitespace around them

    [4.8.22] - 2016-02-02

    Fixed

    • Fixed #2050: PHPUnit_Util_XML::load() raises exception with empty message when XML string is empty
    • Fixed a bug in PHPUnit_Runner_Version::series()

    [4.8.21] - 2015-12-12

    Changed

    ... (truncated)

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • Binary driver on windows

    Binary driver on windows

    Hi, I am trying to convertMS Word template file filled by PHPWord framework to PDF. Found here on Google search and decided to give a try but i get Executable not found, proposed error.

    Where can i find the required binary driver and use it?

    opened by ozilion 2
  • how to upload multiple video in youtube chanel

    how to upload multiple video in youtube chanel

    Hello, Step1. https://developers.google.com/youtube/v3/code_samples/php

    * For more information about using OAuth 2.0 to access Google APIs, please see: * * Please ensure that you have enabled the YouTube Data API for your project. */ $OAUTH2_CLIENT_ID = 'REPLACE_ME'; $OAUTH2_CLIENT_SECRET = 'REPLACE_ME'; $client = new Google_Client(); $client->setClientId($OAUTH2_CLIENT_ID); $client->setClientSecret($OAUTH2_CLIENT_SECRET); $client->setScopes('https://www.googleapis.com/auth/youtube'); $redirect = filter_var('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'], FILTER_SANITIZE_URL); $client->setRedirectUri($redirect); // Define an object that will be used to make all API requests. $youtube = new Google_Service_YouTube($client); // Check if an auth token exists for the required scopes $tokenSessionKey = 'token-' . $client->prepareScopes(); if (isset($_GET['code'])) { if (strval($_SESSION['state']) !== strval($_GET['state'])) { die('The session state did not match.'); } $client->authenticate($_GET['code']); $_SESSION[$tokenSessionKey] = $client->getAccessToken(); header('Location: ' . $redirect); } if (isset($_SESSION[$tokenSessionKey])) { $client->setAccessToken($_SESSION[$tokenSessionKey]); } // Check to ensure that the access token was successfully acquired. if ($client->getAccessToken()) { $htmlBody = ''; try{ // REPLACE this value with the path to the file you are uploading. $videoPath = "/path/to/file.mp4"; // Create a snippet with title, description, tags and category ID // Create an asset resource and set its snippet metadata and type. // This example sets the video's title, description, keyword tags, and // video category. $snippet = new Google_Service_YouTube_VideoSnippet(); $snippet->setTitle("Test title"); $snippet->setDescription("Test description"); $snippet->setTags(array("tag1", "tag2")); // Numeric video category. See // https://developers.google.com/youtube/v3/docs/videoCategories/list $snippet->setCategoryId("22"); // Set the video's status to "public". Valid statuses are "public", // "private" and "unlisted". $status = new Google_Service_YouTube_VideoStatus(); $status->privacyStatus = "public"; // Associate the snippet and status objects with a new video resource. $video = new Google_Service_YouTube_Video(); $video->setSnippet($snippet); $video->setStatus($status); // Specify the size of each chunk of data, in bytes. Set a higher value for // reliable connection as fewer chunks lead to faster uploads. Set a lower // value for better recovery on less reliable connections. $chunkSizeBytes = 1 * 1024 * 1024; // Setting the defer flag to true tells the client to return a request which can be called // with ->execute(); instead of making the API call immediately. $client->setDefer(true); // Create a request for the API's videos.insert method to create and upload the video. $insertRequest = $youtube->videos->insert("status,snippet", $video); // Create a MediaFileUpload object for resumable uploads. $media = new Google_Http_MediaFileUpload( $client, $insertRequest, 'video/*', null, true, $chunkSizeBytes ); $media->setFileSize(filesize($videoPath)); // Read the media file and upload it chunk by chunk. $status = false; $handle = fopen($videoPath, "rb"); while (!$status && !feof($handle)) { $chunk = fread($handle, $chunkSizeBytes); $status = $media->nextChunk($chunk); } fclose($handle); // If you want to make other calls after the file upload, set setDefer back to false $client->setDefer(false); $htmlBody .= "

    Video Uploaded

      "; $htmlBody .= sprintf('
    • %s (%s)
    • ', $status['snippet']['title'], $status['id']); $htmlBody .= '
    '; } catch (Google_Service_Exception $e) { $htmlBody .= sprintf('

    A service error occurred: %s

    ', htmlspecialchars($e->getMessage())); } catch (Google_Exception $e) { $htmlBody .= sprintf('

    An client error occurred: %s

    ', htmlspecialchars($e->getMessage())); } $_SESSION[$tokenSessionKey] = $client->getAccessToken(); } elseif ($OAUTH2_CLIENT_ID == 'REPLACE_ME') { $htmlBody = <<Client Credentials Required

    You need to set \$OAUTH2_CLIENT_ID and \$OAUTH2_CLIENT_ID before proceeding.

    END; } else { // If the user hasn't authorized the app, initiate the OAuth flow $state = mt_rand(); $client->setState($state); $_SESSION['state'] = $state; $authUrl = $client->createAuthUrl(); $htmlBody = <<Authorization Required

    You need to authorize access before proceeding.

    END; } ?>

    Video Uploaded /**

    • Library Requirements
      1. Install composer (https://getcomposer.org)
      1. On the command line, change to this directory (api-samples/php)
      1. Require the google/apiclient library
    • $ composer require google/apiclient:~2.0 */ if (!file_exists(DIR . '/vendor/autoload.php')) { throw new \Exception('please run "composer require google/apiclient:~2.0" in "' . DIR .'"'); }

    require_once DIR . '/vendor/autoload.php'; session_start();

    /*

    • You can acquire an OAuth 2.0 client ID and client secret from the
    • {{ Google Cloud Console }} <{{ https://cloud.google.com/console }}>
    • For more information about using OAuth 2.0 to access Google APIs, please see:
    • https://developers.google.com/youtube/v3/guides/authentication
    • Please ensure that you have enabled the YouTube Data API for your project. */ $OAUTH2_CLIENT_ID = 'REPLACE_ME'; $OAUTH2_CLIENT_SECRET = 'REPLACE_ME';

    $client = new Google_Client(); $client->setClientId($OAUTH2_CLIENT_ID); $client->setClientSecret($OAUTH2_CLIENT_SECRET); $client->setScopes('https://www.googleapis.com/auth/youtube'); $redirect = filter_var('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'], FILTER_SANITIZE_URL); $client->setRedirectUri($redirect);

    // Define an object that will be used to make all API requests. $youtube = new Google_Service_YouTube($client);

    // Check if an auth token exists for the required scopes $tokenSessionKey = 'token-' . $client->prepareScopes(); if (isset($_GET['code'])) { if (strval($_SESSION['state']) !== strval($_GET['state'])) { die('The session state did not match.'); }

    $client->authenticate($_GET['code']); $_SESSION[$tokenSessionKey] = $client->getAccessToken(); header('Location: ' . $redirect); }

    if (isset($_SESSION[$tokenSessionKey])) { $client->setAccessToken($_SESSION[$tokenSessionKey]); }

    // Check to ensure that the access token was successfully acquired. if ($client->getAccessToken()) { $htmlBody = ''; try{ // REPLACE this value with the path to the file you are uploading. $videoPath = "/path/to/file.mp4";

    // Create a snippet with title, description, tags and category ID
    // Create an asset resource and set its snippet metadata and type.
    // This example sets the video's title, description, keyword tags, and
    // video category.
    $snippet = new Google_Service_YouTube_VideoSnippet();
    $snippet->setTitle("Test title");
    $snippet->setDescription("Test description");
    $snippet->setTags(array("tag1", "tag2"));
    
    // Numeric video category. See
    // https://developers.google.com/youtube/v3/docs/videoCategories/list
    $snippet->setCategoryId("22");
    
    // Set the video's status to "public". Valid statuses are "public",
    // "private" and "unlisted".
    $status = new Google_Service_YouTube_VideoStatus();
    $status->privacyStatus = "public";
    
    // Associate the snippet and status objects with a new video resource.
    $video = new Google_Service_YouTube_Video();
    $video->setSnippet($snippet);
    $video->setStatus($status);
    
    // Specify the size of each chunk of data, in bytes. Set a higher value for
    // reliable connection as fewer chunks lead to faster uploads. Set a lower
    // value for better recovery on less reliable connections.
    $chunkSizeBytes = 1 * 1024 * 1024;
    
    // Setting the defer flag to true tells the client to return a request which can be called
    // with ->execute(); instead of making the API call immediately.
    $client->setDefer(true);
    
    // Create a request for the API's videos.insert method to create and upload the video.
    $insertRequest = $youtube->videos->insert("status,snippet", $video);
    
    // Create a MediaFileUpload object for resumable uploads.
    $media = new Google_Http_MediaFileUpload(
        $client,
        $insertRequest,
        'video/*',
        null,
        true,
        $chunkSizeBytes
    );
    $media->setFileSize(filesize($videoPath));
    
    
    // Read the media file and upload it chunk by chunk.
    $status = false;
    $handle = fopen($videoPath, "rb");
    while (!$status && !feof($handle)) {
      $chunk = fread($handle, $chunkSizeBytes);
      $status = $media->nextChunk($chunk);
    }
    
    fclose($handle);
    
    // If you want to make other calls after the file upload, set setDefer back to false
    $client->setDefer(false);
    
    
    $htmlBody .= "<h3>Video Uploaded</h3><ul>";
    $htmlBody .= sprintf('<li>%s (%s)</li>',
        $status['snippet']['title'],
        $status['id']);
    
    $htmlBody .= '</ul>';
    

    } catch (Google_Service_Exception $e) { $htmlBody .= sprintf('

    A service error occurred: %s

    ', htmlspecialchars($e->getMessage())); } catch (Google_Exception $e) { $htmlBody .= sprintf('

    An client error occurred: %s

    ', htmlspecialchars($e->getMessage())); }

    $_SESSION[$tokenSessionKey] = $client->getAccessToken(); } elseif ($OAUTH2_CLIENT_ID == 'REPLACE_ME') { $htmlBody = <<<END

    Client Credentials Required

    You need to set \$OAUTH2_CLIENT_ID and \$OAUTH2_CLIENT_ID before proceeding.

    END; } else { // If the user hasn't authorized the app, initiate the OAuth flow $state = mt_rand(); $client->setState($state); $_SESSION['state'] = $state;

    $authUrl = $client->createAuthUrl(); $htmlBody = <<<END

    Authorization Required

    You need to authorize access before proceeding.

    END; } ?>

    Video Uploaded

    Step2. Go to https://console.developers.google.com and create your project and get credentials step 3. https://developers.google.com/oauthplayground/ and refresh token

    opened by guddukmr51 0
  • Problem is deprecated class

    Problem is deprecated class

    Recently i am receiving the follow warning message

    Mensagem: The Symfony\Component\Process\ProcessBuilder class is deprecated since Symfony 3.4 and will be removed in 4.0. Use the Process class instead.

    My php-unoconv version is 4.1

    opened by cmparrela 0
  • Error: Unoconv failed to transcode file

    Error: Unoconv failed to transcode file

    I have Unoconv on a website with PHP (codeigniter). On my local server (ubuntu) it works perfect, but when I have it on a server in the cloud (ubuntu) it goes wrong when sending transcode.

    Type: Unoconv \ Exception \ RuntimeException

    Message: Unoconv failed to transcode file

    How could I know if it is configuration, permissions or I need to install something on the server?

    opened by vtumialan 1
  • Problem using php-unoconv in laravel application on windows

    Problem using php-unoconv in laravel application on windows

    Hi there,

    I am having some problems using unoconv for file conversion using php-unoconv in laravel. When running unoconv from command prompt it works fine, just that I have to navigate to unoconv directory to run the command

    when running the laravel application for file conversion using php-unoconv, I am getting this error

    ExecutableNotFoundException in AbstractBinary.php line 160: Executable not found, proposed : unoconv

    Thanks

    question 
    opened by uttara010 1
Releases(0.3.1)
Owner
Alchemy
Alchemy
A PHP Emoji conversion library

php-emoji - Process Emoji in PHP This is a PHP library for dealing with Emoji, allowing you to convert between various native formats and displaying t

Cal Henderson 1.3k Dec 16, 2022
PHP FFmpeg - An Object Oriented library to convert video/audio files with FFmpeg / AVConv

PHP FFmpeg An Object Oriented library to convert video/audio files with FFmpeg / AVConv. Check another amazing repo: PHP FFMpeg extras, you will find

Alchemy 10 Dec 31, 2022
the examples of head first object oriented analysis & design - in PHP

Head First object oriented analysis & design in (PHP) after cloning the repository, you have to install the project's dependancies by running the foll

Muhammed ElFeqy 3 Oct 16, 2021
Object-Oriented API for PHP streams

Streamer Streamer is an Object-Oriented API for PHP streams. Why should I use Streams? A stream is a flow of bytes from one container to the other. Yo

Francois Zaninotto 270 Dec 21, 2022
A simple Object Oriented wrapper for Linear API, written with PHP.

PHP Linear API A simple Object Oriented wrapper for Linear API, written with PHP. NOTE You should take a look Linear GraphQL API Schema for all nodes

Mustafa KÜÇÜK 6 Sep 2, 2022
An object oriented wrapper around PHP's built-in server.

Statix Server Requirements PHP 8 minumum Installation composer require statix/server Basic Usage To get started, ensure the vendor autoload script is

Statix PHP 113 Dec 27, 2022
The XP Framework is an all-purpose, object oriented PHP framework.

XP Framework Core This is the XP Framework's development checkout. Installation If you just want to use the XP Framework, grab a release using compose

XP-Framework 17 Dec 14, 2022
Magento2 Plugin for Conversion Pixel/API of Tiktok

Tiktok Conversion Pixel Analytics Plugin Magento2 Table of Contents About Getting Started About Tiktok Pixel is the Plugin used to track events, which

Rishi Gupta 3 Jun 27, 2022
A horrendous PM plugin to manually load all the chunks in your world without logging on. Only for the sole purpose of aiding in PM4 -> DF world conversion.

ChunkLoader A horrendous PM plugin to manually load all the chunks in your world without logging on. Only for the sole purpose of aiding in PM4 -> DF

null 2 Aug 10, 2022
Strings Package provide a fluent, object-oriented interface for working with multibyte string

Strings Package provide a fluent, object-oriented interface for working with multibyte string, allowing you to chain multiple string operations together using a more readable syntax compared to traditional PHP strings functions.

Glowy PHP 14 Mar 12, 2022
Provides an object-oriented API to query in-memory collections in a SQL-style.

POQ - PHP Object Query Install composer require alexandre-daubois/poq 1.0.0-beta2 That's it, ready to go! ?? Usage Here is the set of data we're going

Alexandre Daubois 16 Nov 29, 2022
Provide blocks which allow positioning content within them in layouts.

Mini layouts Provide blocks which allow positioning content within them in layouts. Backdrop Installation Install and enable the module as usual. Go t

Backdrop CMS contributed projects 5 Dec 17, 2021
An article about alternative solution for convert object into a JSON Object for your api.

Do we really need a serializer for our JSON API? The last years I did build a lot of JSON APIs but personally was never happy about the magic of using

Alexander Schranz 1 Feb 1, 2022
Your alter ego object. Takes the best of object and array worlds.

Supporting Opensource formapro\values is an MIT-licensed open source project with its ongoing development made possible entirely by the support of com

FormaPro 31 Jun 25, 2021
Allow any Discord user to sign in to your website and save their discord user information for later use.

Simple Discord SSO ( Single Sign-On ) Requires at least: 5.0 Tested up to: 5.8.3 Stable tag: 1.0.2 Requires PHP: 7.4 License: GPLv2 or later License U

null 2 Oct 7, 2022
NamelessMC is a free, easy to use & powerful website software for your Minecraft server, which includes a large range of features.

NamelessMC is a free, easy to use & powerful website software for your Minecraft server, which includes a large range of features

NamelessMC 519 Dec 31, 2022
Shortest Path - have a function ShortestPath (strArr) take strArr which will be an array of strings which models a non-looping Graph.

Have the function ShortestPath(strArr) take strArr which will be an array of strings which models a non-looping Graph

null 1 Feb 5, 2022
Easy to use utility functions for everyday PHP projects. This is a port of the Lodash JS library to PHP

Lodash-PHP Lodash-PHP is a port of the Lodash JS library to PHP. It is a set of easy to use utility functions for everyday PHP projects. Lodash-PHP tr

Lodash PHP 474 Dec 31, 2022
Supper quick use Aliyun OSS or Tencent COS or Qiniu Koa to get、put、delete Object.

An SDK integrating Alibaba cloud, Tencent cloud and qiniu cloud object storage

null 6 Sep 26, 2021