I found this code online, and it allows me to draw signaures with.gs and.html.
function doGet() {
return HtmlService
.createTemplateFromFile('index')
.evaluate();
}
function saveToDrive(signature){
var signature = signature.split(",")
var blob = Utilities.newBlob(Utilities.base64Decode(signature[1]), 'image/png');
var sheet=SpreadsheetApp.getActive().getActiveSheet();
sheet.insertImage(blob, 1, 1);
}
<!DOCTYPE html>
<html>
<head><meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0"/></head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdn.rawgit.com/willowsystems/jSignature/master/libs/jSignature.min.js"></script>
<body>
<form>
...
Signature:
<div id="signature"></div><br>
<img id="rendered" src="" style="display:none">
<input type="Submit" value="Save" onclick="getSignature();"/>
...
</form>
</body>
<script>
document.getElementById("signature").style.border = "1px solid black";
$("#signature").jSignature({
'background-color': 'transparent',
'decor-color': 'transparent'
});
function getSignature(){
$("img#rendered").attr("src",$('#signature').jSignature('getData','default'));
var signature = document.getElementById('rendered').src;
google.script.run.saveToDrive(signature);
}
</script>
</html>
I just want to know how I intergrate it within my form, so that at the bottom, there is a place to sign, which then automatically saves to my google drive as a jpg, and is shown in my form as an image.
For this:
saveToDrive
function tofunction saveToDrive(signature){
var signature = signature.split(",")
var blob = Utilities.newBlob(Utilities.base64Decode(signature[1]), 'image/png');
blob.setName("signature");
var file = DriveApp.createFile(blob);
}
Execute the app as:
Me
, Who has access to the app:
Anyone, even anonymous
.Here is a sample form (keep in mind that the WebApp is deployed as me, so if you provide a signature, it will be saved on my Drive and not yours ):
https://docs.google.com/forms/d/e/1FAIpQLSckCxKzrUdNvpcONLVRvJ08e5EDZRNB-tTfSRKG2YRLVjI_Ww/viewform
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.