使用 Google Apps 脚本将 Google 幻灯片保存为 PDF

Save Google Slide as PDF using Google Apps Script

是否可以使用 Google Apps 脚本将 Google 幻灯片另存为 PDF 文件?

我只能找到保存 Google 文档和表格的解决方案。

这个示例脚本怎么样?当 Google 文档(电子表格、文档和幻灯片)保存 and/or 使用 DriveApp.createFile() 下载时,文件格式自动变为 PDF。所以我们可以使用下面的脚本。

示例脚本:

var blob = DriveApp.getFileById("### Slide file ID ###").getBlob();
DriveApp.createFile(blob);

注:

在这种情况下,创建的PDF文件的文件名与幻灯片相同。

编辑:

如果要复制幻灯片文件,请使用以下脚本。

var file = DriveApp.getFileById("### Slide file ID ###");
file.makeCopy(DriveApp.getFolderById("### Destination folder ID ###"));

这可以通过用 SlideApp 替换 DocumentApp 来实现

请注意,如果驱动器文件夹中存在以前创建的同名 pdf,它还会删除它。

function onOpen() {
  var ui = DocumentApp.getUi();
  ui.createMenu('Save PDF copy')
  .addItem('Save PDF', 'SavePDF')
  .addToUi();
}

function SavePDF() {
  var theDoc = DocumentApp.getActiveDocument();
  var id = DocumentApp.getActiveDocument().getId()
  var ui = DocumentApp.getUi();
  var folderString = DriveApp.getFileById(id).getParents().next().getName();
  var folder = DriveApp.getFileById(id).getParents().next();

  var theBlob = theDoc.getAs('application/pdf')
  var thePDFName = theBlob.getName()

  var theFiles = DriveApp.getFilesByName(theBlob.getName())
  while (theFiles.hasNext()) {
    var theFile = theFiles.next()
    if (theFile.getParents().next().getName() == folderString) {
      theFile.setTrashed(true)
    }
   }

  var newFile = folder.createFile(theBlob);
  ui.alert('Saved to ' + folderString + " " + theBlob.getName())
}
let pdf =  DriveApp.getFileById(copySlide.getId())
              .getBlob()
              .getAs("application/pdf");
pdf.setName("filename.pdf");
let file = DriveApp.getFolderById(FOLDER_ID).createFile(pdf);