大佬教程收集整理的这篇文章主要介绍了是否可以使用 AppScript 下载 Google 幻灯片中的当前幻灯片?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我想以 pdf 格式下载在谷歌幻灯片中打开的当前页面。 Google 幻灯片允许在他们自己的用户界面中将整个演示文稿下载为 pdf,但我有兴趣一张一张地下载演示文稿中的幻灯片。
现在我可以选择当前页面,
export const getCurrentPage = () => {
return SlIDesApp.getActivePresentation()
.getSELEction()
.getCurrentPage();
};
此函数返回一个 Page Class。
问题是我不知道如何将这个“页面类”转换为 pdf 并下载它。我已经检查了可用的方法,但还没有找到任何有用的东西。有什么建议吗?
Save Google Slide as PDF using Google Apps Script 将整个幻灯片文件转换为 PDF 并将其保存到您的 Google Drive。如果您想在本地计算机上下载特定幻灯片,可以参考示例代码。
function onOpen() {
// get the UI for the Spreadsheet
const ui = SlidesApp.getUi();
// add the menu
const menu = ui.createMenu("Download")
.addItem("Download Current Slide",'downloadModal')
.addToUi();
}
function downloadModal() {
var pdfFile = convertToPdf();
//Get the pdf file's download url
var html = "<script>window.open('" + pdfFile.getDownloadUrl() + "');google.script.host.close();</script>";
var userInterface = Htmlservice.createHtmlOutput(html)
.setHeight(10)
.setWidth(100);
SlidesApp.getUi().showModalDialog(userInterface,'Downloading PDF ... ');
//delete pdf file in the drive
pdfFile.setTrashed(true);
}
function convertToPdf() {
//Get current slide
var presentation = SlidesApp.getActivePresentation();
var slide = presentation.getSELEction().getCurrentPage().asSlide();
Logger.log(slide.getObjectId());
//Create temporary slide file
var tmpPresentation = SlidesApp.create("tmpFile");
//delete default initial slide
tmpPresentation.getSlideById("p").remove();
//Add current slide to the temporary presentation
tmpPresentation.insertSlide(0,slidE);
tmpPresentation.saveAndClose();
//Create a temporary pdf file from the temporary slide file
var tmpFile = DriveApp.getFileById(tmpPresentation.getId());
var pdfFile = DriveApp.createFile(tmpFile.getBlob().setName("slide.pdf"))
//delete temporary slide file
tmpFile.setTrashed(true);
return pdfFile;
}
将当前幻灯片转换为 PDF 文件:
注意:
文件中的第一张幻灯片有一个 object id = 'q'
,您可以在浏览器中查看幻灯片 url 中的对象 ID#slide=id.<object id>
下载文件:
downloadModal()
将当前幻灯片下载到本地计算机中convertToPdf()
以获取 pdf 文件的 File 对象。使用 File.getDownloadUrl()
以上是大佬教程为你收集整理的是否可以使用 AppScript 下载 Google 幻灯片中的当前幻灯片?全部内容,希望文章能够帮你解决是否可以使用 AppScript 下载 Google 幻灯片中的当前幻灯片?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。