PHP code example of conversiontools / conversiontools-php
1. Go to this page and download the library: Download conversiontools/conversiontools-php library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
conversiontools / conversiontools-php example snippets
onversionTools\ConversionToolsClient;
$client = new ConversionToolsClient([
'api_token' => 'your-api-token',
]);
$client->convert('convert.pdf_to_word', 'input.pdf', 'output.docx');
$client->convert('convert.xml_to_csv', 'data.xml', 'data.csv', [
'delimiter' => 'tabulation',
]);
$client->convert('convert.website_to_pdf', ['url' => 'https://example.com'], 'result.pdf');
$fileId = $client->files->upload('input.pdf');
$client->convert('convert.pdf_to_word', ['file_id' => $fileId], 'output.docx');
$fileId = $client->files->upload('input.pdf');
$task = $client->createTask('convert.pdf_to_word', ['file_id' => $fileId]);
$task->wait([
'on_progress' => function (array $status): void {
echo "{$status['conversionProgress']}% [{$status['status']}]\n";
},
]);
$task->downloadTo('output.docx');
$taskId = $client->convert(
conversionType: 'convert.pdf_to_word',
input: 'input.pdf',
wait: false,
callbackUrl: 'https://your-app.com/webhook',
);
use ConversionTools\Exceptions\ConversionToolsException;
use ConversionTools\Exceptions\RateLimitException;
use ConversionTools\Exceptions\ConversionException;
try {
$client->convert('convert.pdf_to_word', 'input.pdf', 'output.docx');
} catch (RateLimitException $e) {
echo "Quota exceeded. Daily remaining: {$e->limits['daily']['remaining']}\n";
} catch (ConversionException $e) {
echo "Conversion failed for task {$e->taskId}: {$e->taskError}\n";
} catch (ConversionToolsException $e) {
echo "Error [{$e->errorCode}]: {$e->getMessage()}\n";
}
$limits = $client->getRateLimits();
// ['daily' => ['limit' => 30, 'remaining' => 25], 'monthly' => [...]]
bash
composer