google-doc-to-pdf
📝Generate PDF from Google Doc templates
google-doc-mustaches
HEADS UP!: This package has been renamed toHow does this work?
google-doc-to-pdf will execute requests to the Google Drive and Google Docs APIs to copy the file, interpolate its placeholders and generate the according PDF.
Installation
npm install google-doc-to-pdf
Basic usage
Create a new Google Doc file and write the following text:
Hello {{ firstname }} {{ lastname | uppercase }}!
You have {{ accounts[0].money }}€ in you account...
Then execute the following code
const gdoc = gapiauthaccess_token // ID of the templateconst source = '11rGORd6FRxOGERe7fh6LNQfyB48ZvOgQNH6GScK_FfA' // ID of the destination folderconst destination = '18mcqwbaXS8NOqZjztB3OUQAc5_P8M6-l' gdoc
Documentation
new GoogleDocToPdf(options: GoogleDocToPdfOptions)
token
will be called at every request to the Google apis.
AccessToken must have the following scopes:
gdoc.toPdf(source: ID, destination?: ID, options?: ToPdfOptions): ID
This method will create a new Google Doc file from the source
and into the destination
folder.
If options.data
is provided, this method will try to interpolate placeholders from the source file.
name
will be the name of both the newly created and completed google doc file and the corresponding PDFdata
will be used for interpolationformatters
will be used for interpolation
Interpolation
Mustaches
The double brackets notation (also known as mustaches) is used to define placeholders:
My name is {{ firstname }}. Nice to meet you!
During the interpolation, the placeholder will be replaced with the content of the options.data
object.
firstname: 'Thibaud'
My name is Thibaud. Nice to meet you!
Path notation
You can use nested objects and arrays for the interpolation:
{{ pokemons[1].name }}, I choose you!
With the following options.data
pokemons: name: 'Eevee' level: 12 name: 'Pikachu' level: 25
Will become:
Pikachu, I choose you!
Formatters
You can use formatters to print your data and more complex objects any way you want.
There is a number of available formatters, but you can also write your owns
Hi {{ name | uppercase }}. Today is {{ today | printDay }}, tomorrow is {{ tomorrow | printDay }}.
With the following options
:
data: name: "Courtoison" today: tomorrow: formatters: date
Will become:
Hi COURTOISON. Today is Thursday, tomorrow is Wednesday.
Available formatters:
- lowercase:
HeLLo
=>hello
- uppercase:
wOrLd
=>WORLD
- More to come...