How to convert a Rasterized PDF into a DOCX in PHP

Cloudmersive
2 min readApr 24, 2020

--

Whatever your reasons might be for converting a rasterized PDF into a Word document, the setup process for this functionality is quite a drag. That is, unless you use this lovely API that I am going to demonstrate here today.

With this command for composer, we can begin. Running it from the command line will install our API client and permit us to continue.

composer require cloudmersive/cloudmersive_document_convert_api_client

Second step, calling our function:

<?phprequire_once(__DIR__ . '/vendor/autoload.php');// Configure API key authorization: Apikey$config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKey('Apikey', 'YOUR_API_KEY');// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed// $config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKeyPrefix('Apikey', 'Bearer');$apiInstance = new Swagger\Client\Api\ConvertDocumentApi(// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.// This is optional, `GuzzleHttp\Client` will be used as default.new GuzzleHttp\Client(),$config);$input_file = "/path/to/file"; // \SplFileObject | Input file to perform the operation on.try {$result = $apiInstance->convertDocumentPdfToDocxRasterize($input_file);print_r($result);} catch (Exception $e) {echo 'Exception when calling ConvertDocumentApi->convertDocumentPdfToDocxRasterize: ', $e->getMessage(), PHP_EOL;}?>

Now we are finished, with our only remaining task to input our PDF for conversion. Take a moment and think about the amount of time you just saved.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

No responses yet