Nota client API - aerix-nl/nota GitHub Wiki

Nota.trigger() events

If you're using a scripted, data driven template and either need more time for initialization or rendering, or are annoyed with the inefficient use of timeouts because your template renders very quickly, you can choreograph rendering and capture timing with the backend. The Nota object exposes the trigger function, which can be called with a string, coding an event, which will be sent to the backend.

'template:init:start'

This cancels the automatic template initialization timeout, and essentially promises that your template will signal when it's done with initialization. This gives you (practically) as much time as you want. There are however several timeouts in config-default.json, like templateInitSlow for generating a warning when taking very long, and templateInitDead for detecting a crashed template. These can be overridden by your template using a nota.json declaration.

'template:init:done'

Signal that the template has finished initialization and is ready to receive data.

'template:render:start'

Cancels the automatic render timeout, and gives you control similarly to the initialization start event. See the respective timeouts in the config for edge cases.

'tempalte:render:done'

Signal that the template has finished rendering the data, and is ready to be captured to it's build target. Your template should set any optional meta data before calling this.

Nota.setDocumentPropety()

Per data render job your template can provide Nota with some data about the current current document capture. Just before the caputure the Nota backend will request this data from the respective document properties using the Nota.getDocumentProperty(property); interface on the client.

Meta data

Use Nota.setDocumentProperty('meta', metaData) to set a object hash containing meta data about the data render job your template just finished. It could look like

metaData = {
  filename: 'Invoice_2014.0042-Client_Name.pdf'
}

So far, only the filename property of the hash is used by Nota, but you can extend it with whatever data you like. This can be handy if your building an application that uses the Nota API for generating documents, and want to receive additional meta data per job. See the Nota.queue backend API about how this data is retrieved.

The filename property provides a way for the Nota backend to 'asks' your template for a suggested filename and build target (derived from the filename extension). If no output filename is provided with the Nota backend API call (or the output path in the job hash is a directory), then this filename will be used. In the same manner, you can provide a filename without a file extension if you want to specify per job when calling the backend API.

Footer

NOTICE! Broken due to bug in PhantomJS (Nota dependency)

Use Nota.setDocumentProperty('footer', footerProperties) to set a object hash containing like this:

footerProperties = {
  height: "1cm"
  contents: "<footer>Page <strong>{{pageNum}}</strong> of {{numPages}}</footer>"
}

Height can be any CSS like height expression, and contents a simple Handlebars.js like HTML template string. Only simple variable string interpolation is supported, not full Handlebars templating!

By default, the backend will attempt try apply the styling of your template. If this fails, you can disable it using

footerProperties.sampleStyles = false

and instead apply your own styles manually using inline styling on the style attribute.

⚠️ **GitHub.com Fallback** ⚠️