How to Convert RTF to JPG in Node.JS

If you are having a difficult time in turning your documents into images, then look no further. Today, we will be making this task incredibly simple (the way it should be) by eliminating the matter of coding entirely from the process. We can do this by harnessing an API to take care of things for us. This is easy, as you will soon see.

First comes installation:

npm install cloudmersive-convert-api-client --save

Next, our function call for convertDocumentRtfToJpg, which simply takes in your RTF document as its input.

var CloudmersiveConvertApiClient = require('cloudmersive-convert-api-client');var defaultClient = CloudmersiveConvertApiClient.ApiClient.instance;// Configure API key authorization: Apikeyvar Apikey = defaultClient.authentications['Apikey'];Apikey.apiKey = 'YOUR API KEY';// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)//Apikey.apiKeyPrefix = 'Token';var apiInstance = new CloudmersiveConvertApiClient.ConvertDocumentApi();var inputFile = "/path/to/file"; // File | Input file to perform the operation on.var opts = {'quality': 56 // Number | 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.};var callback = function(error, data, response) {if (error) {console.error(error);} else {console.log('API called successfully. Returned data: ' + data);}};apiInstance.convertDocumentRtfToJpg(inputFile, opts, callback);

And now you’re done! Super easy. For a whole lot more useful conversion functions like this one, take a peek at the rest of this library.

Image for post
Image for post

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store