【发布时间】:2021-05-17 01:28:25
【问题描述】:
Google Apps 脚本
- 我想为 Google 幻灯片文件的每张幻灯片创建 PDF 文件(带有文字和图表的普通幻灯片)。
- 我回顾了过去的问题,发现了一种解决方案,它可以生成 PDF 文件,但将幻灯片作为图像(我需要能够搜索这些 pdf 中的单词)。
- 应用了另一种解决方案来转换电子表格 -> PDF,但它也不适用于我的情况。
function autoFlyerGenerator() {
const name_file = "FILE_NAME";
// Template file in Google slide
const ppt_file = DriveApp.getFileById(##SLIDE_ID##);
// Temporal folder to store a temporal slide file
const temp_folder = DriveApp.getFolderById(##TEMP_FOLDER_ID##);
// PDF folder
const pdf_folder = DriveApp.getFolderById(##PDF_FOLDER_ID##);
// My current spreadsheet
const ss = SpreadsheetApp.getActive();
const values_ss = ss.getDataRange().getValues();
const temp_ppt = ppt_file.makeCopy(temp_folder).setName(name_file);
const open_temp_ppt = SlidesApp.openById(temp_ppt.getId());
const slides = open_temp_ppt.getSlides();
// First for-loop iterate over all rows (without the header)
// Second for-loop iterate over all columns
for (var index = 0; index < ss.getLastRow()-1; index++){
for (var col = 0; col < ss.getLastColumn(); col++){
slides[index].replaceAllText(values_ss[0][col], values_ss[index+1][col])
}
}
open_temp_ppt.saveAndClose();
// This code block create a single PDF of the slide
const pdfContentBlob = temp_ppt.getBlob();
pdf_folder.createFile(pdfContentBlob).setName(name_file);
}
更新
- 我忘了提到 Google 幻灯片文件的页面设置大小与默认大小不同。
- 这个问题的第一个答案解决了生成pdf文件的问题,但是没有考虑幻灯片的大小。
【问题讨论】:
标签: javascript google-apps-script google-slides