Sorry guys, I decided to drop this project. After discussing with a few people about it, it seems this solution won’t fit for all, thus it is not worth the time it will cost to develop it.
However, here is the general outline of the idea if someone wants to develop it:
USER INTERFACE
1- make a template manager, storing HTML templates, and using CKeditor as the frontend. This interface should offer an example template, and should be able to store new templates saved by the user. Variables substitution should work just like with ODT, but with HTML tags to format your page in addition.
2- when you want to generate your document, you should be able to see the template in the templates drop-down list (on the module’s page, along other templates), with two choices for each one: one for ODT, and one for PDF generation.
Eg: your template is called “mylittletemplate”, you should see in the list “mylittletemplate.odt” and “mylittletemplate.pdf”
3- Generate and you get your document in the file format you want. Thus you just need to make one template, and you can generate in any format you want later.
DEV PART
To make this system work, the basic idea is that we start from an HTML template, which will then be processed into a templating system to substitute variables and expand products’ lines, then finally we can convert the resulting HTML code to pretty much any format we want (there are many converters HTML -> whatever, while there’s no ODT -> PDF nor PDF -> ODT).
To detail the whole process:
1- Make the HTML templates manager, using CKeditor as the interface. Simply store each template in the database as a “text()” sql datatype.
2- Make the HTML templates be shown inside the dropdown list of templates on modules’ pages.
3- At document generation:
A. Preprocess the template: using the user defined HTML template, we use TinyButStrong as a templating system to substitute variables and to expand products’ lines, similarly to what does the library odtPHP. In addition, using TinyButStrong will offer more freedom to users to make their own expandable data collections (we can imagine that we in fact expand any data array related to a Dolibarr object, not just products’ lines, but also contacts, etc.).
This is actually the trickiest part, but also the most rewarding one.
B. Convert to a file format: now that the final HTML output is formatted, we can just convert it to any file format, for example using OpenTBS to convert to ODT (or even .DOC !). To convert to PDF, there are plenty of HTML to PDF libraries, like HTML2PDF and here’s another one.
ADVANTAGE
The main advantage of this framework is of course that with only one template, you would be able to generate pretty much any kind of file format. Also, it would be quite easy to add the support for the generation of a new file format, it would only be a matter of plugging in an HTML->your format converter.
Another advantage would be that we would have a very powerful templating system, allowing to do all kind of fancy dynamic templates.
Lastly, the management of variables substitution would be unified, and probably the template generator could be too, instead of having one PDF + one ODT generator for each module. The only thing that would change here would be the variables substituted, but with a clever design, it would only be a matter of variables in the HTML templates, no change in the php code.
SHORTCOMINGS
The main limitation people told me about this framework would be that, indeed, using CKeditor you would lose the ability to view your template per page (you would only see an undefinitely long HTML page, no Word-like page view).
However, you can set page breaks in CKeditor.