1

I have a question on how the following approach could be implemented / is feasible for using GoogleDrive, GoogleDocs, GoogleSheets via API as a PDF generator and document storage from templates where the templates itself are stored on the users GoogleDrive for a user in a proprietary app.

Basic Steps would look like this:

  1. Create folders named "templates", "invoices" and "letters" in a users GoogleDrive

  2. Create template files like "invoice" and "letter" in the "templates" folder from a pre-defined "master-template" (containing the users logo, contact info, etc. with multiple {placeholders} for the actual content to be filled in later

  3. the user writes a letter in the app, maybe in simple markdown

  4. the app sends the content in JSON representation to a Google Apps Script which in turn takes the appropriate template from the users "templates" folder and fills in the placeholders with the content

  5. the newly created document gets saved as a PDF and put in the users GoogleDrive in the folder called "invoices"

Potential benefits:

  • the user is able to the layout/formatting of his own templates in GoogleDrive, newly generated files use the user's modified template for creation
  • the apps uses GoogleDrive as a pdf generator and document storage
Thomas
  • 446
  • 4
  • 10

1 Answers1

2

I have never successfully made an API call to a google script, but it looks like you can, read here.

To answer the other part of your question. Can you make templates, input data, then save them as PDFs? Yes, I have done this for many projects. What you are looking for is Mail Merge. There are many tutorials on how to create a Mail Merge.

You will be using something like .replaceText('<tag>',tag) which is under DocumentApp.

Converting a google doc to pdf is easy, all you need is this:

 var pdf = DriveApp.getFileById(docId).getAs("application/pdf"); 

Then you can save or send that file anywhere.

If you know how to make OAuth API calls to google services then you should be fine, that is the hardest part to me. The other parts you will find much information on, and tutorials.

Mullenb
  • 651
  • 6
  • 20