使用JavaScript创建Powerpoint [英] Create Powerpoint with JavaScript
问题描述
JavaScript无法在客户端文件系统上本地创建文件。但是,我想知道,如果有可能以某种方式在某个JSON的网页(div或iframe)中创建一个Powerpoint MIME,然后让UserAgent弄清楚它是Powerpoint,期望UserAgent将为用户提供选择将其显示为powerpoint演示文稿?
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?
注意:这里的想法是能够获取一些JSON并进行powerpoint演示,而无需向服务器发出创建Powerpoint文件的请求。
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.
推荐答案
可以生成Powerpoint二进制文件的一个JavaScript库是 PptxGenJS 。
One JavaScript library that can generate Powerpoint binary files is PptxGenJS.
从一般来说,您可以使用具有Powerpoint MIME类型的数据URL创建链接:
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
运行您的逻辑以创建二进制Powerpoint文件,然后对其进行base64编码(例如,使用 btoa
),然后动态生成链接或将 window.location
重定向到数据URI。
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);
我的假设 createPowerpointFromJSON
函数可能会调用PptxGenJS API或任何其他生成Powerpoint的API。
My hypothetical createPowerpointFromJSON
function might make calls to the PptxGenJS API, or any other Powerpoint-generating API.
这篇关于使用JavaScript创建Powerpoint的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!