SDK for onlineconvertfree.com file conversion API.
PHP 7.4 and later. Should also work with PHP 8.0.
The recommended way to install SDK is through Composer.
composer require webpractik/ocf-converter-sdk
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;
}
SDK is made available under the MIT License (MIT). Please see License File for more information.
OpenAPI Generator is used for the client generation.
JRE and OpenAPI Generator are required for the client generation.
To regenerate the client do the following:
- run generation command:
composer api-codegen
- reformat the generated code with your IDE.