ObeoNetwork / M2Doc

The M2Doc technology enables the generation of Office Open XML documents from models.
http://obeonetwork.github.io/M2Doc/
Eclipse Public License 2.0
38 stars 22 forks source link

Dynamic pagination and page sizes #445

Closed dsryzhov closed 1 week ago

dsryzhov commented 2 years ago

We need to generate documents with dynamic pagination and page sizes. I know about possibility to add dynamic pagination. But I don't know whether is it possible to change page size dynamically for current section.

One possible approach that I think of is to have some M2Doc command that will change page sizes dynamically. Is it difficult to implement this feature in M2Doc? Can you give some advise on architecture for me to be able to implement this feature by myself?

Another possible approach that I think of is to use different templates for different sections to generate different documents (one per section) and merge them after generation using POI api. I used POI api before to merge m2Doc templates from several small templates. Now I think I can use the same approach but merge generated documents.

ylussaud commented 2 years ago

If you can define directly those sections in the template, it should work out of the box. Did you tried it ? For instance by calling an AQL expression inside a defined section. If needed you can also add an IF statement around the section so it will not appear if not needed.

If the sections really need to be dynamic for the first approach you can have a look at the way pagination is inserted here. I guess you could add an element (MSection ?) with parameters and use Apache POI you insert the section. But at some point you will probably need to end this section, an other MSectionEnd ? I don't really know how sections are stored in the docx file.

The last approach can be easier to implement but a bit complicated to use.

dsryzhov commented 2 years ago

Thanks for your comments! I will take some additional experiments and will write the results.

dsryzhov commented 2 years ago

I've selected the second approach. At the first step generate separate documents using different templates. At the second step merge generated documents. When merging documents section breaks are inserted.

In each template different page size and orientation can be used.

To be more productive with this approach I've created metamodel for modeling document structure. Document model consists of sections and parts. Every section and part can be connected to elements of the original EMF model. Every section and part can define template to be used. For every section and part variables can be defined. This variables are transitioned to the template during generation.

This document model is an expanded version of genconf model with the possibility to define document structure.

And I've created generator for this document model. It iterates sections and parts in the document model, generate separate documents and after that merge them into one document.

The main features for the second aproach