Skip to content

Instantly share code, notes, and snippets.

@barrieroberts
Last active April 2, 2021 15:12
Show Gist options
  • Save barrieroberts/6c480a0d5d6414d12088380465cdca61 to your computer and use it in GitHub Desktop.
Save barrieroberts/6c480a0d5d6414d12088380465cdca61 to your computer and use it in GitHub Desktop.
6-Convert Doc to PDF
//Convert Doc to PDF
function example61() {
//Make copy of Doc
const masterDoc = DriveApp.getFileById('ADD YOUR DOCUMENT ID HERE');
const newDoc = masterDoc.makeCopy("EXAMPLE 61 - Company document");
const newDocId = newDoc.getId();
//create a PDF file from this Doc
const pdf = DriveApp.getFileById(newDocId).getAs('application/pdf');
pdf.setName(newDoc.getName() + ".pdf");
const docPdf = DriveApp.createFile(pdf);
//Add a copy of pdf in doc folder, delete original pdf, & delete orig Doc
const folder = DriveApp.getFolderById('ADD YOUR FOLDER ID HERE');
docPdf.moveTo(folder);
DriveApp.getFileById(newDocId).setTrashed(true);
}
//Create image of a map
function example62() {
const map = Maps.newStaticMap().setCenter('Chepstow castle, Chepstow, UK');
DriveApp.createFile(map);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment