Corrupted statistics analyzer
Triplecorpse opened this issue · comments
Thank you for the module provided, it helps me a lot in my job. However, I would like to count number of pages in newly created document and it seems it fails to count. Here I provide the code and template. I run it with Node:
const templates = require("docx-templates");
const fsp = require("fs/promises");
(async function() {
const tpl = await fsp.readFile("tpl.docx")
const uint = await templates.createReport({
template: tpl,
data: {
text: "I love docx-templates".repeat(500)
}
})
await fsp.writeFile("ext2.docx", uint);
const file = await fsp.readFile("ext2.docx");
const metadata = await templates.getMetadata(file);
debugger;
})();
My node version is:
C:\Users\eldar>node --version
v18.11.0
docx-templates version:
"docx-templates": "4.9.2",
docx-template statistics (1 page and everything else is incorrect):
Note: when I modify and save file in Word, the statistics counter begins to work as it should
Note 2: the same issue happens if I make Buffer.from(uint)
without saving file
These statistics and other metadata can only be updated by Word after saving the file. Docx-templates only edits the xml of the docx file. You need a renderer like MS Word to actually count the number of pages that the docx file produces. I dont think it is possible to count the number of pages without rendering the entire file.