Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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);
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: show the time zone of browser javascript 
Javascript :: npm request 
Javascript :: $.post javascript 
Javascript :: what does document.getelementbyid return 
Javascript :: jquery on change on multiple elements 
Javascript :: Fetching data with React hooks and Axios 
Javascript :: eslint disable next line multiple rules 
Javascript :: create object from array 
Javascript :: how to copy text from input through button click js 
Javascript :: react radio button checked not working 
Javascript :: import firebase auth react 
Javascript :: how to add lang attribute in next js 
Javascript :: append http to url 
Javascript :: findone mongoose 
Javascript :: callback function 
Javascript :: how to make a grocery list in javascript 
Javascript :: axios post request with authorization header and body 
Javascript :: how to add items to object in javascript 
Javascript :: Disable/remove pagination from react material-table 
Javascript :: javascript static variable in class 
Javascript :: socketio connect websockets 
Javascript :: javascript template literals html 
Javascript :: prepend option on 2nd index jquery 
Javascript :: react context api with hooks 
Javascript :: jest add alias 
Javascript :: node.js error handling process 
Javascript :: javascript es6 find 
Javascript :: clear input field data in jquery 
Javascript :: js local file read to blob variable 
Javascript :: compare date and time in js 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =