Converting google document to pdf using Scrips
function convertPDF() {
doc = DocumentApp.getActiveDocument();
// ADDED
var docId = doc.getId();
var docFolder = DriveApp.getFileById(docId).getParents().next().getId();
// ADDED
var ui = DocumentApp.getUi();
var result = ui.alert(
'Save As PDF?',
'Save current document (Name:'+doc.getName()+'.pdf) as PDF',
ui.ButtonSet.YES_NO);
if (result == ui.Button.YES) {
docblob = DocumentApp.getActiveDocument().getAs('application/pdf');
/* Add the PDF extension */
docblob.setName(doc.getName() + ".pdf");
var file = DriveApp.createFile(docblob);
// ADDED
var fileId = file.getId();
moveFileId(fileId, docFolder);
// ADDED
ui.alert('Your PDF file is available at ' + file.getUrl());
} else {
ui.alert('Request has been cancelled.');
}
}
//placing a document into the correct folder.
function moveFileId(fileId, toFolderId) {
var file = DriveApp.getFileById(fileId);
var source_folder = DriveApp.getFileById(fileId).getParents().next();
var folder = DriveApp.getFolderById(toFolderId)
folder.addFile(file);
source_folder.removeFile(file);
}