Create ID cards and Send Emails Using Google Apps Script

Step 1: Sample Google Form

Step 2: Writing the Automation Script

function After_Submit(e){const info = e.namedValues;const pdfFile = Create_PDF(info);console.log(info);sendEmail(e.namedValues['Email Address'][0],pdfFile);}
sendEmail(e.namedValues['Email Address'][0],pdfFile);
function sendEmail(email,pdfFile){GmailApp.sendEmail(email, "ID CARD", "This is your ID Card.", {attachments: [pdfFile],});}
const PDF_folder = DriveApp.getFolderById("1zx7rnI2M3p2U7RGTJugM_0G5aMINYTyh");const TEMP_FOLDER = DriveApp.getFolderById("1jO1BHwhwkKbGFcyT8DAJsew2v0gjCI4W");const PDF_Template =DriveApp.getFileById("1qHOMwuq2X_5LhUCfPLWcpUSh2n7pVRvHZ_kE-hsGmwg");const newTempFile = PDF_Template.makeCopy(TEMP_FOLDER);const  OpenDoc = DocumentApp.openById(newTempFile.getId());const body = OpenDoc.getBody();console.log(body);
const newTempFile = PDF_Template.makeCopy(TEMP_FOLDER);const  OpenDoc = DocumentApp.openById(newTempFile.getId());const body = OpenDoc.getBody();console.log(body);
body.replaceText("{email}", info['Email Address'][0])body.replaceText("{name}", info['Enter your name'][0]);body.replaceText("{roll}", info['Enter your Roll number'][0]);body.replaceText("{number}", info['Enter your phone number '][0]);body.replaceText("{DOB}", info['Enter you Date of Birth '][0]);body.replaceText("{BLOOD}", info['Enter your Blood Group  [Eg:  O negative]'][0]);OpenDoc.saveAndClose();
const BLOBPDF = newTempFile.getAs(MimeType.PDF);const pdfFile =  PDF_folder.createFile(BLOBPDF).setName(info['Enter your name'][0] + " " + info['Enter your Roll number'][0]);console.log("The file has been created ");return pdfFile;}

Summary

Currently pursuing B Tech at MPSTME. Technical Blogger, interested in Google Workspace. Hope to remain a life long student. Created a course on Google Classroom

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store