Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate libreoffice text document programmatically from template

I'm trying to find a way to generate an .odt document from an .ott template programmatically. This should be done programmatically. Any ideas on how to achieve this?

I found some ways of generating .odt files in Java (http://incubator.apache.org/odftoolkit/odfdom/index.html) but there seems no possibility to generate a document from an .ott template.

The implementing language is more or less irrelevant but the best would be JavaScript on Node.js.

Thanks for your help in advance.

like image 863
domachine Avatar asked Dec 05 '13 01:12

domachine


2 Answers

I wrote an utility in python called Secretary to create ODT documents from ODT templates. You can check it at https://github.com/christopher-ramirez/secretary maybe it could help you. The next version will support adding images to rendered documents.

like image 53
Christopher Ramírez Avatar answered Sep 23 '22 16:09

Christopher Ramírez


Have you checked node-odt? It seems to me it supports what you need.

According with its documentation:

A node js tool to work with OpenDocument text files.

and one of its example:

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;
  })
  .finalize(function(bytes){
    console.log('The document is ' + bytes + ' bytes large.');
  })
  .pipe(createWriteStream('mydocument.odt'))
  .on('close', function(){
    console.log('document written');
  });
like image 42
Diosney Avatar answered Sep 22 '22 16:09

Diosney