我有一個幻燈片演示文稿,其中包含鏈接到電子表格的圖表。我想在一個 PDF 檔案中創建此幻燈片所有頁面的 PDF 副本以用于分發。我從@Tanaike 找到了一個腳本,除了添加一些內容外,它還可以作業。
- 所有幻燈片頁面必須復制到一個 PDF 檔案中。
- 必須能夠選擇需要復制為 PDF 的頁面。
- 如果可能,請包含一個腳本以自動通過電子郵件發送 PDF 副本。非常感謝您的任何幫助。
當前腳本:
function myFunction2() {
const folderId = "13Un85DDcMiW_ACHC1Tncrgaqt_DP5cg3"; // Please set the folder ID you want to put the exported PDF files.
// 1. Retrieve all slides from the source Google Slides.
const slide = SlidesApp.getActivePresentation();
const srcId = slide.getId();
const srcSlides = slide.getSlides();
// 2. Create a temporal Google Slides.
const file = DriveApp.getFileById(srcId).makeCopy("temp");
const id = file.getId();
let temp = SlidesApp.openById(id);
temp.getSlides().forEach((e, i) => {
if (i != 0) e.remove();
});
const folder = DriveApp.getFolderById(folderId);
// 3. Export each page as a PDF file.
srcSlides.forEach((s, i) => {
temp.appendSlide(s);
temp.getSlides()[0].remove();
temp.saveAndClose();
folder.createFile(file.getBlob().setName(`page_${i 1}.pdf`));
temp = SlidesApp.openById(id);
});
// 4. Remove the temporal Google Slides.
file.setTrashed(true);
}
uj5u.com熱心網友回復:
我相信你的目標如下。
- 您想通過選擇 Google 幻燈片中的特定幻燈片將 Google 幻燈片轉換為 PDF 檔案。
- 您希望將創建的 PDF 檔案作為電子郵件的附件發送。
- 您想通過修改顯示腳本來實作此目的。
在這種情況下,如何進行以下修改?從您的演示腳本中,我認為您可能已經使用了這個示例腳本。在此腳本中,每張幻燈片都創建為每個 PDF 檔案。這樣,這個示例腳本就不會被直接使用。
當這個腳本被修改以實作你的目標時,下面的修改怎么樣?
修改后的腳本:
在使用此腳本之前,請設定檔案夾 ID 和所選頁碼以及您要發送的電子郵件地址。在此腳本中,使用選定的頁碼匯出特定幻燈片。
function myFunction3() {
const folderId = "root"; // Please set the folder ID you want to put the exported PDF files.
const selectedPages = [1, 2, 3, 5]; // Please set the selected page numbers.
const emailAddress = "###"; // Please set the email address.
// 1. Retrieve all slides from the source Google Slides.
const slide = SlidesApp.getActivePresentation();
const srcId = slide.getId();
// 2. Create a temporal Google Slides.
const file = DriveApp.getFileById(srcId).makeCopy("temp");
const id = file.getId();
let temp = SlidesApp.openById(id);
const tempSlides = temp.getSlides();
for (let i = tempSlides.length - 1; i >= 0; i--) {
if (!selectedPages.includes(i 1)) {
tempSlides[i].remove();
}
}
// 3. Export each page as a PDF file.
temp.saveAndClose();
const blob = file.getBlob().setName(`${file.getName()}.pdf`);
DriveApp.getFolderById(folderId).createFile(blob);
// 4. Remove the temporal Google Slides.
file.setTrashed(true);
// 5. Send email.
MailApp.sendEmail({ to: emailAddress, subject: "sample subject", body: "sample text body", attachments: [blob] });
}
運行此腳本時,會選擇特定幻燈片并將其轉換為 PDF 資料,并將其創建為 PDF 檔案,然后將其作為電子郵件附件發送。
在此示例中,
const selectedPages = [1, 2, 3, 5]使用了。在這種情況下,將匯出 1、2、3、5 頁的幻燈片。
Note:
If you don't want to create a file, please remove
DriveApp.getFolderById(folderId).createFile(blob);.Unfortunately, I couldn't understand the method for selecting the specific slides from
Must be able to select pages that needs to be copied as PDF.. So in this sample, I used an array including the page numbers. If this was not the direction, please modify it.
References:
- remove() of Class Slide
- sendEmail(message)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/452740.html
