Created
November 10, 2021 00:04
Star
You must be signed in to star a gist
Google Docs from a folder and converts it into a PDF
This file contains 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 characters
function doGet(){return HtmlService.createHtmlOutputFromFile("index")} | |
function myFunction() { | |
var folderId = " "; // folder with docs | |
var moveToFolderId = " "; // folder to move PDF | |
var doneFolderId = " "; // folder with docs that have already been converted to PDF (to reduce duplication) | |
var filesN = DriveApp.getFolderById(folderId).getFiles(); | |
var downloadedFolder = DriveApp.getFolderById(moveToFolderId); | |
var doneFolder = DriveApp.getFolderById(doneFolderId); | |
while(filesN.hasNext()){ | |
var doc = filesN.next(); | |
doc.moveTo(doneFolder); | |
var docName = doc.getName(); | |
docBlob = doc.getAs('application/pdf'); | |
docBlob.setName(docName + ".pdf"); | |
var file = downloadedFolder.createFile(docBlob); | |
Logger.log('Your PDF file is available at ' + file.getUrl()); | |
} | |
} |
This file contains 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 characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<base target="_top"> | |
</head> | |
<style> | |
body{ | |
padding:5%; | |
font-family:arial; | |
} | |
header{ | |
border-radius:10px; | |
padding:1em; | |
box-shadow: 0px 5px 10px #e6e6e6; | |
} | |
#status{ | |
display:none; | |
margin: 0.5em 0; | |
padding: 1em; | |
border-radius:5px; | |
} | |
#status div{ | |
padding:0; | |
margin:0; | |
display:flex; | |
gap:1em; | |
flex-direction:row; | |
align-items:center; | |
} | |
#doneId{ | |
color:#4c8bf5; | |
margin: 0.5em 0 1.5em 0; | |
padding: 0.8em 1em; | |
border-radius:5px; | |
} | |
button{ | |
cursor:pointer; | |
width: auto; | |
border-radius: 5px; | |
background: #4c8bf5; | |
font-weight:bold; | |
color: #fff; | |
outline: none; | |
border: none; | |
padding: 15px; | |
transition: .5s; | |
} | |
button:hover{ | |
box-shadow: 0 1px 5px lightblue; | |
} | |
</style> | |
<script> | |
function startConversion(){ | |
google.script.run.withSuccessHandler(createUpdate).myFunction(); | |
document.getElementById("status").style.display = 'block'; | |
} | |
function createUpdate(){ | |
document.getElementById("status").style.display = 'none'; | |
var done = document.createElement('div'); | |
done.setAttribute('id', 'doneId'); | |
done.innerHTML = "<h3>✓ Successfully Converted!</h3>"; | |
document.getElementById("updates").appendChild(done); | |
} | |
</script> | |
<body> | |
<header> | |
<h1>Doc to PDF Converter</h1> | |
</header> | |
<ol> | |
<li>Instructions go here</li> | |
</ol> | |
<div id="updates"> | |
<div id="status"> | |
<div> | |
<img width="40" height="40" src="https://c.tenor.com/I6kN-6X7nhAAAAAj/loading-buffering.gif"> | |
<p>Loading, please wait.</p> | |
</div> | |
</div> | |
</div> | |
<button onclick="startConversion();">Convert Doc to PDF</button> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment