guigrpa/docx-templates

Metadata is returning wrong number of pages

Ademking opened this issue ยท 4 comments

Thank you so much for this library. It's so helpful.

I have this bug... Metadata is returning wrong page number... the final document is 47 pages but it's showing 5

I think it's because of HTML content? Maybe?

image

image

  • Runtime environment; NodeJs
  • Version: 4.8.0

I'm using HTML content inside a FOR Loop... example

+++HTML `
<body>
  ${$t.code}
</body>
`+++

Is your template document 5 pages long?

jjhbw commented

The number of pages is simply grabbed from a docx XML metadata element. It can only feasibly be determined by a docx renderer, like MS Word or LibreOffice.
The document needs to be rendered by e.g. Word at least once before the length of the document can be known. Word will update the 'number of pages' metadata element when saving the document. You are probably looking at the number of pages of your template because the metadata hasn't been updated yet, like @mathe42 says.

In more technical terms: I don't think the length of the document can be determined just by static analysis of the docx XML; the XML needs to be rendered. The pages metadata is just a reflection of that.

@mathe42: Yes. It's 5 pages

@jjhbw: I get it now... So i can't get the exact number using metadata
Thank you guys for the help ๐Ÿ‘๐Ÿ‘
Keep up the good work

jjhbw commented

๐Ÿ‘ Great. Yes, this seems to be a hard limitation. Sorry I couldn't give a more satisfying answer.