How to Replace Strings in a PowerPoint Presentation using Node.JS

Cloudmersive
2 min readDec 11, 2020

When sharing PowerPoint documents among various clients and stakeholders, it can be useful to personalize the content where possible. This provides a more professional and personal style to the presentation without needing to drastically change the content. The following API will allow you to replace all instances of a text string in a PPTX file.

The parameters for this function include the input file or file URL, the match string and its replacement string, and an option for matching the case of the replaced string, which can be useful when replacing proper nouns.

To use this API, run this command to install the SDK:

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

You can also add this snippet to your package.json:

"dependencies": {
"cloudmersive-convert-api-client": "^2.4.8"
}

Then, you can call the function:

var CloudmersiveConvertApiClient = require('cloudmersive-convert-api-client');
var defaultClient = CloudmersiveConvertApiClient.ApiClient.instance;
// Configure API key authorization: Apikey
var Apikey = defaultClient.authentications['Apikey'];
Apikey.apiKey = 'YOUR API KEY';
var apiInstance = new CloudmersiveConvertApiClient.TransformDocumentApi();var matchString = "matchString_example"; // String | String to search for and match against, to be replacedvar replaceString = "replaceString_example"; // String | String to replace the matched values withvar opts = {
'inputFile': Buffer.from(fs.readFileSync("C:\\temp\\inputfile").buffer), // File | Optional: Input file to perform the operation on.
'inputFileUrl': "inputFileUrl_example", // String | Optional: URL of a file to operate on as input. This can be a public URL, or you can also use the begin-editing API (part of EditDocumentApi) to upload a document and pass in the secure URL result from that operation as the URL here (this URL is not public).
'matchCase': true // Boolean | Optional: True if the case should be matched, false for case insensitive match. Default is false.
};
var callback = function(error, data, response) {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + data);
}
};
apiInstance.transformDocumentPptxReplace(matchString, replaceString, opts, callback);

This will return an output file with the results of the text string replacement. You can retrieve the API Key from Cloudmersive at no cost and with no commitment. This will give you access to 800 monthly calls across our library of APIs.

--

--

Cloudmersive

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