Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create Powerpoint with JavaScript

JavaScript cannot create files locally on the clients filesystem. However, I am wondering, if it is possible to somehow create a Powerpoint MIME in a web page (a div or a iframe) from some JSON and then let the UserAgent figure out it is Powerpoint in the expectation that the UserAgent will offer the user the choice to display it as a powerpoint presentation?

Note: The idea here is to be able to take some JSON and make a powerpoint presentation without having to make a request to a Server to create a Powerpoint file.

like image 677
dublintech Avatar asked Aug 27 '12 14:08

dublintech


People also ask

Can you use JavaScript in PowerPoint?

A PowerPoint add-in interacts with objects in PowerPoint by using the Office JavaScript API, which includes two JavaScript object models: PowerPoint JavaScript API: The PowerPoint JavaScript API provides strongly-typed objects that you can use to access objects in PowerPoint.

Can you use HTML in PowerPoint?

HTML files are objects supported in PowerPoint, so you can use the "Insert object" function to link to a web page document on your hard drive. Run Microsoft PowerPoint and open the presentation to which you want to add the HTML object.


1 Answers

One JavaScript library that can generate Powerpoint binary files is PptxGenJS.

Genreally speaking, you can create a link with a data URL that has a Powerpoint MIME type:

 data:ms-powerpoint;base64,aGVsbG8gd... // base64-encoded file

Run your logic to create a binary Powerpoint file, then base64-encode it (e.g. with btoa), and then dynamically generate a link or redirect window.location to the data URI.

var binaryPPFile = createPowerpointFromJSON(sourceJSON);
window.location = "data:ms-powerpoint;base64," + btoa(binaryPPFile);

My hypothetical createPowerpointFromJSON function might make calls to the PptxGenJS API, or any other Powerpoint-generating API.

like image 65
apsillers Avatar answered Oct 23 '22 17:10

apsillers