ngs-doo / TemplaterExamples

Creating reports in .NET and Java
https://templater.info
The Unlicense
48 stars 27 forks source link

page plugin generating more pages than necessary #19

Closed DanielWalter-MXP closed 4 years ago

DanielWalter-MXP commented 4 years ago

Hello, I am having a problem while using the plugin :page

Given the following json model and word document for the template it generates far more pages than necessary and many are without content or printing directly the page

JsonModel Template Example Result

Not sure if there is a better way of making the model print one page per instance of the tag [OrdemProducao.Operacao.InsumoBaixado.MovimentacaoDeBaixa.EstoqueOrigem.Item.Descricao]

Thank you.

zapov commented 4 years ago

Yeah, it seems that :page does not behave as expected here as it is called on every subcollection up to your leaf.

Alternative way to get similar behavior is to put one extra tag outside of the table, to force using whole page as resize context. It is preferable to use some tag on the same level, such as: [[OrdemProducao.Operacao.InsumoBaixado.MovimentacaoDeBaixa.EstoqueOrigem.Item.CEST]:hide] but you can also put root object tag after the table, such as [[OrdemProducao.Operacao.InsumoBaixado.MovimentacaoDeBaixa.EstoqueOrigem.Item]:hide]

btw. this long tag names are not really a fortunate thing in Word tables. We'll look into a solution to that problem.

DanielWalter-MXP commented 4 years ago

Unfortunately, using: [[OrdemProducao.Operacao.InsumoBaixado.MovimentacaoDeBaixa.EstoqueOrigem.Item]:hide] still didn't produce the expected result, it should be 8 pages, but instead it generated 13 pages, the 8 related to "MovimentacaoDeBaixa" and 5 more without any content on the tags, just the base model as if didn't had tags on it.

Model generate in the process

I will wait for the fix then.

zapov commented 4 years ago

I looked more closely into this.

So there are several problems here. The main problem is that your JSON does not follow the expected output layout. Eg you have nested arrays in nested arrays, but expect a single flat list (meaning at most 1 array)

What happens is that whole document gets resized whenever a collection with more than 1 element is encountered. Eg it goes from 1 (template) -> 5 (Operacao) -> 10 (5 x 2 InsumoBaixado) ...

The best workaround you can do is put sections around your table, but if you want to have each table on a new page you will have to put page break before the table which will result in first page empty ;(

So all in all, this is actually working as expected since original page metadata causes even more whole document duplications

ps. there is an improvement for this long tag in a Word table problem via aliases in new version :tada:

DanielWalter-MXP commented 4 years ago

Thank you for the help, changing the template to instead of iterating in the Operacao -> InsumoBaixado, to iterate in Insumo->MovimentacaoBaixa worked.