B4J Question [SOLVED] How to Add Page Numbers to WordDocument Class in B4J?

jroriz

Active Member
Licensed User
Longtime User
Is there a tag or a method to include page numbers in the WordDocument class? I'm looking for a way to automatically insert page numbers into my document generated using the WordDocument class in B4J. Any guidance or examples would be greatly appreciated.

B4X:
    Dim wd As WordUtils

    wd.Initialize
    Dim doc As WordDocument = wd.CreateDocument

    doc.Append($"
        [header]
            [p]this text will go to the header - PAGENUMBER? [/p]
        [/header]"$)
...
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
 
Upvote 0

PaulMeuris

Active Member
Licensed User
Here's another example using the new version (2.08) of XLUtils.
I have added a few FieldCode tags (DATE, PAGE, NUMPAGES) in the header from the WordExample from Erel:
1722602243020.png

B4X:
[header]
    [p][FieldCode=DATE/]${TAB}${TAB}${TAB}${TAB}${TAB}[FieldCode=PAGE/] of [FieldCode=NUMPAGES/]${TAB}${TAB}${TAB}${TAB}${TAB}${TAB}[img dir=assets filename=logo.png width=30 height=30/][/p]
    [p][img dir=assets filename="blue_line.png" width=470 height=2/][/p]
[/header]
The blue line image serves as a bottom border in a second paragraph of the header.
In the footer the blue line appears closer and is in the same paragraph:
1722602371231.png

B4X:
[footer]
    [p][img dir=assets filename="blue_line.png" width=470 height=2/]Generated automatically...${TAB}${TAB}${TAB}${TAB}${TAB}${TAB}${TAB}${TAB}${TAB}[FieldCode=PAGE/] of [FieldCode=NUMPAGES/][/p]
[/footer]
TABs are used to position the code texts in the paragraph.
Tip: make sure to put the closing / in the FieldCode tags.
With the underline tag the contents of the fields are not underlined.
 
Upvote 0
Top