docx
docx copied to clipboard
I want to add the Page Number inside the paragraph.
Hi everyone, I can add the total number of pages to the title section. but I want to use the total number of pages inside the page. how can I do that. Thanks.
its a work.
headers: {
default: new Header({
children: [
new Paragraph({
children: [
new TextRun("Foo Bar corp. "),
new TextRun({
children: ["Page Number ", PageNumber.CURRENT],
}),
new TextRun({
children: [" to ", PageNumber.TOTAL_PAGES],
}),
],
}),
],
}),
},
but its a not work.
children: [
new Paragraph({
children: [new TextRun(`${PageNumber.TOTAL_PAGES}`), new PageBreak()],
}),
new Paragraph({
children: [new TextRun("Hello World 2"), new PageBreak()],
}),
new Paragraph({
children: [new TextRun("Hello World 3"), new PageBreak()],
}),
new Paragraph({
children: [new TextRun("Hello World 4"), new PageBreak()],
}),
new Paragraph({
children: [new TextRun("Hello World 5"), new PageBreak()],
}),
],
me too
Been doing a lot of research, I do not think this is possible actually
I found that, page number cannot be retrieved using openxml element. We can approximate it. But we cannot be sure. Because Page numbers are rendered by word processor layout engine. This happens after all the OpenXML elements are passed to word processor.
Pages do not exist in the OpenXML format until they are rendered by a word processor.
docx can calculate it, but that's not simple.
Source: https://stackoverflow.com/questions/43700252/how-to-get-page-numbers-based-on-openxmlelement