How to Convert an RTF File to JPG in PHP

2 min readJul 1, 2021


Rich Text Format documents are not the easiest format to work with — their compatibility with other programs is low and the potential to end up with a corrupted file by opening it with the wrong program is high. To simplify transforming an RTF document into an array of JPG/JPEG images (one for each page of the document), you can use the following API in PHP.

First, we will run this command to install the SDK:

composer require cloudmersive/cloudmersive_document_convert_api_client

Then, we can call the conversion function with the following code:

require_once(__DIR__ . '/vendor/autoload.php');
// Configure API key authorization: Apikey
$config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKey('Apikey', 'YOUR_API_KEY');
$apiInstance = new Swagger\Client\Api\ConvertDocumentApi(

new GuzzleHttp\Client(),
$input_file = "/path/to/inputfile"; // \SplFileObject | Input file to perform the operation on.
$quality = 56; // int | Optional; Set the JPEG quality level; lowest quality is 1 (highest compression), highest quality (lowest compression) is 100; recommended value is 75. Default value is 75.
try {
$result = $apiInstance->convertDocumentRtfToJpg($input_file, $quality);
} catch (Exception $e) {
echo 'Exception when calling ConvertDocumentApi->convertDocumentRtfToJpg: ', $e->getMessage(), PHP_EOL;

And just like that, your new JPG file will be ready to download. To retrieve an API key, visit the Cloudmersive website and register for a free account; this provides 800 calls/month across our entire library of APIs.




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