Template definition file - aerix-nl/nota GitHub Wiki

It's highly recommended to add a definition for Nota to your template, in the form of nota.json in the root of your template directory. An example of such a file (from the example invoice template shipped with Nota CLI):

{
  "name": "aerix-invoice-nota-template",
  "exampleData": "json/preview.json",
  "defaultFilename": "example-invoice.pdf",
  "paperSize": {
    "format": "A4",
    "orientation": "portrait",
    "margin": {
      "top": "15mm",
      "left": "21mm",
      "right": "21mm",
      "bottom": "15mm",
      "deferHorizontal": true,
      "deferVertical": false
    },
    "border": "0cm"
  },
  "timeouts": {
    "resourcesLoaded":      1500,
    "templateInitSlow":     500,
    "templateInitDead":     2000,
    "templateRenderSlow":   500,
    "templateRenderDead":   2000,
    "errorAbort":           1000
  }
}

name

Just for readability convenience and identification. Can be any plain text string.

exampleData

Recommended for use cases like development and previewing your template in the browser.

defaultFilename

Fallback filename in case no output filename is specified with a render job, and the template doesn't propose a filename using the client's Nota.setDocumentProperty('meta', metaOptions) API. If no build target is specified with a job, Nota will also use this default filename to check for an file extension that matches with a supported build target (also see the About build targets page).

paperSize

These options are passed to PhantomJS for capture. See their documentation.

Nota adds some functionality to this:

Deferred margins at rendertime

PhantomJS allows you to set margins for the capture of a page. These margins essentially shrink the page viewport as to leave whitespace around it in the capture output. This is useful for when you have a multi-page document and you don't want to have your content flow down the page to the very bottom, and then start at the very top of the next page. Hence, setting vertical the margins here will ensure beautiful multipage rendering. These kind of margins are undeferred; handled by PhantomJS.

You might want to defer the horizontal margins when you want to be able to use the full horizontal width of your document (for example for notes or icons in the margins, or some full page width banner image). This this case, set deferred margins to true, and PhantomJS will leave it's capture margins to 0, giving the template full access to the available paper space, from edge to edge. You might wonder what the use of specifying the margins here is then? It is as a logical central place of declaring margins used by whatever code might also need it. One example is the build script of the example invoice template which needs the paper size and margins in the browser stylesheet. It generates the paper size stylesheet using the template definition file.

timeouts

These will override the defaults in the Nota default-config.json. Leave omitted the use the defaults. You can use this override to tighten the timings of your render loop and increase performance. Use carefully, because too tight timeouts will mistake a heavy render job for a crashed one and kill it prematurely.

resourcesLoaded
templateInitSlow
templateInitDead
templateRenderSlow
templateRenderDead
errorAbort