Skip to content

webpractik/ocf-converter-sdk-php

Repository files navigation

ocf-converter-sdk

SDK for onlineconvertfree.com file conversion API.

Installation & Usage

Requirements

PHP 7.4 and later. Should also work with PHP 8.0.

Composer

The recommended way to install SDK is through Composer.

composer require webpractik/ocf-converter-sdk

Getting Started

Please follow the installation procedure and then start from the following:

<?php
require_once(__DIR__ . '/vendor/autoload.php');


$apiKey = 'myApiKey';

$client = new Webpractik\OcfConverter\Sdk\OcfClient($apiKey);

$filePath = '/path/to/file/to/convert.png';
$extensionToConvertTo = 'pdf';

try {
    $task = $client->uploadFile($filePath, $extensionToConvertTo);

    $result = $task->waitForConversion();

    if ($result->isSuccess()) {
        $resultUrl = $result->getResultingFileUrl();

        $resultFileName = basename($resultUrl);

        if (file_put_contents($resultFileName, file_get_contents($resultUrl))) {
            $result->deleteFile();
        }
    }
} catch (Exception $e) {
    echo 'Exception: ', $e->getMessage(), PHP_EOL;
}

License

SDK is made available under the MIT License (MIT). Please see License File for more information.

Contribution

OpenAPI Generator is used for the client generation.

Requirements

JRE and OpenAPI Generator are required for the client generation.

Client generation

To regenerate the client do the following:

  • run generation command:
composer api-codegen
  • reformat the generated code with your IDE.