1. Go to this page and download the library: Download converthub/php-sdk 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/ */
converthub / php-sdk example snippets
ConvertHub\ConvertHubClient;
// Initialize the client
$client = new ConvertHubClient('YOUR_API_KEY');
// Convert a file
$job = $client->conversions()->convert(
'path/to/document.pdf',
'docx'
);
// Wait for completion
$completedJob = $client->jobs()->waitForCompletion($job->getJobId());
// Get download URL
if ($completedJob->isCompleted()) {
echo "Download URL: " . $completedJob->getDownloadUrl();
}
// Get download info
$downloadInfo = $client->jobs()->getDownloadUrl($job->getJobId());
echo "Filename: " . $downloadInfo->getFilename() . "\n";
echo "Size: " . $downloadInfo->getFileSizeFormatted() . "\n";
// Download to local file
$success = $downloadInfo->downloadTo('path/to/save/converted.docx');
if ($success) {
echo "File downloaded successfully!\n";
}
// Simple - extract text and wait for result
$job = $client->ocr()->imageToTextAndWait('path/to/scan.png');
// Download the extracted text
$downloadInfo = $client->jobs()->getDownloadUrl($job->getJobId());
$downloadInfo->downloadTo('output/extracted.txt');
// Async - submit and poll manually
$job = $client->ocr()->imageToText('path/to/scan.png');
echo "Job ID: " . $job->getJobId() . "\n";
$completedJob = $client->jobs()->waitForCompletion($job->getJobId());
use ConvertHub\Models\OcrOptions;
// Extract text from a scanned PDF
$job = $client->ocr()->pdfToTextAndWait('path/to/scanned.pdf');
// With options - force OCR even if text layer exists
$job = $client->ocr()->pdfToTextAndWait(
'path/to/scanned.pdf',
OcrOptions::make()->language('eng')->forceOcr()
);
// Create a searchable PDF from an image (adds invisible text layer)
$job = $client->ocr()->imageToSearchablePdf('path/to/scan.png');
// Add OCR text layer to an existing scanned PDF
$job = $client->ocr()->makeSearchablePdf('path/to/scanned.pdf');
use ConvertHub\Models\OcrOptions;
$options = OcrOptions::make()
->language('eng+deu') // Multiple languages with '+'
->deskew() // Straighten skewed scans
->rotatePages() // Auto-detect page rotation
->removeBackground() // Remove background noise
->clean() // Clean up image before OCR
->forceOcr() // OCR all pages, even with existing text
->dpi(300) // Higher DPI for better accuracy
->pageSegmentationMode(6) // Single uniform block of text
->outputFilename('result.txt')
->metadata(['batch' => 'invoice_scan_2024']);
$job = $client->ocr()->imageToTextAndWait('scan.png', $options);
// Check if a format is supported
if ($client->formats()->isSupported('heic')) {
echo "HEIC format is supported\n";
}
// Check if a specific conversion is supported
if ($client->formats()->isConversionSupported('pdf', 'docx')) {
echo "PDF to DOCX conversion is available\n";
}
// Get all possible conversions for a format
$conversions = $client->formats()->getConversions('png');
echo "PNG can be converted to:\n";
foreach ($conversions['available_conversions'] as $conversion) {
echo " - {$conversion['target_format']}\n";
}