Giter Site home page Giter Site logo

php-unoconv's Introduction

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

php-unoconv's People

Contributors

bitdeli-chef avatar romainneutron avatar xorti avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

php-unoconv's Issues

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?

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.

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?

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

How to get php-unoconv / unoconv working for Ubuntu 14.04?

Most times, any issue with using php-unoconv actually lies in the interaction between unoconv, the libreoffice/openoffice, and the operating system's python modules.

I think to increase more adoption for this php-unoconv, it is good to add more documentation around the area of installing unoconv, libreoffice/openoffice, and the operation system.

I can contribute to the use of this in Ubuntu 14.04 64-bit Server edition using Python 2.7

  1. git clone directly from the unoconv repo. Forget about ever using the packages standard unoconv. It is usually broken.
  2. copy the unoconv file into the /usr/bin/unoconv
  3. Uninstall all versions of open office and libreoffice and follow this https://gist.github.com/luw2007/d5ce9b5e5a27be77054a. Stop at step 4.
  4. Use this test script to make sure that unoconv itself is okay.

testunoconv.php

putenv('HOME=/var/www/');

    $command = 'echo $HOME &  unoconv -vvvv --format %s --output %s %s 2>full_path_to_output.txt';
    $command = sprintf($command, 'pdf', 'full_path_to_output.pdf', 'full_path_to_input.docx');
    exec($command, $output, $result_var);
  1. Look for the output.txt and you should expect to see something like this:
Verbosity set to level 4
DEBUG: Connection type: socket,host=127.0.0.1,port=2002,tcpNoDelay=1;urp;StarOffice.ComponentContext
DEBUG: Existing listener not found.
DEBUG: Launching our own listener using /opt/openoffice4/program/soffice.bin.
Input file: full_path_to_input.docx
DEBUG: Terminating OpenOffice instance.
DEBUG: Waiting for OpenOffice instance to exit.
  1. Even if you don't see this, there will be some useful error messages that you can use to google your way out of this. I highly recommend that php-unoconv include this as a function somewhere for testing purposes. I couldn't have solved the issue without this logger. The logger example given did not set verbosity to vvvv
  2. Once you can get unoconv to work, it is matter of using php-unoconv

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.

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

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; } ?>

<!doctype html>

<title>Video Uploaded</title> /**

  • 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();

/*

$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; } ?>

<!doctype html>

<title>Video Uploaded</title>

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

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.