Last active
November 17, 2023 20:05
-
-
Save pkorpine/c7efed52086147916c951ce2211465e5 to your computer and use it in GitHub Desktop.
Revisions
-
pkorpine revised this gist
May 31, 2021 . No changes.There are no files selected for viewing
-
pkorpine revised this gist
May 31, 2021 . 1 changed file with 5 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,7 @@ // Saves the current document in Google Docs as PDF to the same folder. // Code from https://stackoverflow.com/questions/28312992/convert-google-doc-to-pdf-using-google-script-editior // Just added onOpen() to add the script to the menubar. function onOpen() { var ui = DocumentApp.getUi(); // Or DocumentApp or FormApp. @@ -6,7 +10,7 @@ function onOpen() { .addToUi(); } function convertPDF() { doc = DocumentApp.getActiveDocument(); // ADDED -
pkorpine created this gist
May 31, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,42 @@ function onOpen() { var ui = DocumentApp.getUi(); // Or DocumentApp or FormApp. ui.createMenu('My scripts') .addItem('Convert to PDF', 'convertPDF') .addToUi(); } // https://stackoverflow.com/questions/28312992/convert-google-doc-to-pdf-using-google-script-editior 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.'); } } 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); }