如何将Google幻灯片下载为图片? [英] How to download Google Slides as images?
问题描述
我非常喜欢将Google幻灯片作为云托管的轻量级插画替代品(这也恰好是协作和免费!)。我在这里写了一些关于我的流程的想法:
我在工作流程中要做的是将演示文稿中的所有幻灯片下载为图片立刻? Google幻灯片用户界面只允许您将每张幻灯片一次下载为PNG格式吗?
这可以使用附加软件或Apps脚本吗?不知道从哪里开始......谢谢!
以下方法适用于我:
设置
在资源>开发人员控制台项目> View Developers Console 下,启用幻灯片API 和 Drive API 。
执行
调用 downloadPresentation(id)
,其中包含从幻灯片网址获取的ID,例如:
https ://docs.google.com/presentation/d/< id> / edit
和功能会将PNG保存到您的云端硬盘。这可以扩展到将它们全部放在一个特定的文件夹中。
function downloadPresentation(id){
var slideIds = getSlideIds(id); $ i
$ b(var i = 0,slideId; slideId = slideIds [i]; i ++){
downloadSlide('Slide'+(i + 1),id,slideId);
函数downloadSlide(name,presentationId,slideId){
var url ='https://docs.google.com/presentation/d/ '+ presentationId +
'/ export / png?id ='+ presentationId +'& pageid ='+ slideId;
var options = {
headers:{
授权:'Bearer'+ ScriptApp.getOAuthToken()
}
};
var response = UrlFetchApp.fetch(url,options);
var image = response.getAs(MimeType.PNG);
image.setName(name);
DriveApp.createFile(image);
}
函数getSlideIds(presentationId){
var url ='https://slides.googleapis.com/v1/presentations/'+ presentationId;
var options = {
headers:{
授权:'Bearer'+ ScriptApp.getOAuthToken()
}
};
var response = UrlFetchApp.fetch(url,options);
var slideData = JSON.parse(response);
return slideData.slides.map(function(slide){
return slide.objectId;
});
}
I am a big fan of using Google Slides as a cloud-hosted lightweight illustrator replacement (that also happens to be collaborative and free!). I wrote up a few thoughts on my process here:
What I'm trying to do in my workflow is download all of the slides in a presentation as images at once? The Google Slides UI only lets you download each slide as a PNG one at a time?
Is this possible using add-ons or Apps Scripts somehow? Not sure where to start... Thanks!
The following worked for me:
Set up
Under Resources > Developer Console Project > View Developers Console, enable both the Slides API and the Drive API.
Execution
Call downloadPresentation(id)
with the ID taken from the Slides URL, e.g.:
https://docs.google.com/presentation/d/<id>/edit
and the function will save the PNGs to your Drive. This could be extended to group them all in a specific folder etc.
function downloadPresentation(id) {
var slideIds = getSlideIds(id);
for (var i = 0, slideId; slideId = slideIds[i]; i++) {
downloadSlide('Slide ' + (i + 1), id, slideId);
}
}
function downloadSlide(name, presentationId, slideId) {
var url = 'https://docs.google.com/presentation/d/' + presentationId +
'/export/png?id=' + presentationId + '&pageid=' + slideId;
var options = {
headers: {
Authorization: 'Bearer ' + ScriptApp.getOAuthToken()
}
};
var response = UrlFetchApp.fetch(url, options);
var image = response.getAs(MimeType.PNG);
image.setName(name);
DriveApp.createFile(image);
}
function getSlideIds(presentationId) {
var url = 'https://slides.googleapis.com/v1/presentations/' + presentationId;
var options = {
headers: {
Authorization: 'Bearer ' + ScriptApp.getOAuthToken()
}
};
var response = UrlFetchApp.fetch(url, options);
var slideData = JSON.parse(response);
return slideData.slides.map(function(slide) {
return slide.objectId;
});
}
这篇关于如何将Google幻灯片下载为图片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!