odt

A node tool to work with OpenDocument text files.

node-odt

A node js tool to work with OpenDocument text files.

  $ npm install odt
var fs = require('fs')
  , odt = require('odt')
  , template = odt.template
  , createWriteStream = fs.createWriteStream
var doc = 'mytemplate.ott';
var values = { 'subject': 'My subject value' };
 
// apply values 
 
template(doc)
  .apply(values)
  .on('error', function(err){
    throw err;
  })
  .on('end', function(doc){
 
    // write archive to disk. 
 
    doc.pipe(createWriteStream('mydocument.odt'))
    doc.finalize(function(err){
      if (err) throw err;
      console.log('document written!');
    });
  });

For a more advanced example see the command line utility in bin/node-odt.

The main class to work with templates. It inherits from EventEmitter and fires the following events:

  • error - Fired if an error occurs.
  • end(document) - Fired when the document is complete.

Applies the values to the template. values is an object of the following form:

{
  "field-type": {
    "field-name": "field-value"
  }
}

e.g.

{
  "string": {
    "subject": "My subject",
    ...
  },
  ...
}