Hi coders.
I want to share my google app script code. With this app script code, you can generate certificates, the bill received, proof card, and much more from your google document template.
If you are interested to add this feature to your app you can follow my steps.
- Open your Google drive and make a new folder.
- Generate a share link of your google drive folder.
- Make your google Doc template into the new drive folder.
- Create a Google app script file and paste the code.
function doPost (e) { var tags = e.parameter.tags.split(","); var values = e.parameter.values.split(","); var name = e.parameter.name; var driveFolder = DriveApp.getFolderById(e.parameter.folder); var doc = DriveApp.getFileById(e.parameter.tem); return docs(tags, values, name, driveFolder, doc); } function docs(tags, values, name, driveFolder, doc) { var copy = doc.makeCopy(driveFolder).setName("tamp"+ name); var document = DocumentApp.openById(copy.getId()); var body = document.getBody(); tags.forEach(function(tag){ body.replaceText(tag, values[tags.indexOf(tag)]); }); document.saveAndClose(); var pdf = copy.getAs(MimeType.PDF); var pdffile = driveFolder.createFile(pdf).setName(name); var download = "https://drive.google.com/uc?export=download&id="+pdffile.getId(); copy.setTrashed(true); return ContentService.createTextOutput(download); };
-
Rename the app script file and deploy it as a webapp and make it anyone accessible.
-
Copy and save the deploy link.
-
Now you need to make a procedure.
-
You got the PDF download link by this block. ( direct download link )
How it,s work?
Basically, it’s just replacing some text from your template and make a pdf file.
I’m not good at English, and I know I didn’t understand you very well. So if you have any problems you can send me a message. Forgive me if I make a mistake
Thank you