Page 1 of 1

Page m of n in footer reverts to default style

PostPosted: Tue Mar 05, 2019 7:14 pm
by Grytpype
I've just had LibreOffice upgraded, and a macro no longer works quite right. As part of reformatting a document it puts "Page m of n" in small print in the footer. It still does this, but now only the word "Page" appears in the small print, while the " of " and the two variable numbers have reverted to the default font and size. The relevant code is:
Code: Select all   Expand viewCollapse view
FTR_FONT = "Calibri"
FTR_SIZE = 8
' Short names for stupidly named things
kARABIC = com.sun.star.style.NumberingType.ARABIC
kPAGENO = "com.sun.star.text.textfield.PageNumber"
kPAGECT = "com.sun.star.text.textfield.PageCount"
' . . .
cur4 = style.footertext.text.createtextcursor
cur4.charfontname = FTR_FONT
cur4.charheight = FTR_SIZE
' . . .
pageno = doc.createinstance(kPAGENO)
pageno.numberingtype = kARABIC ' default is A, B, C ...!
pageno.subtype = 1 ' subtype 1 = use current page no.
pagect = doc.createinstance(kPAGECT)
pagect.numberingtype = kARABIC
style.footertext.text.insertstring(cur4, chr(9) & "page ", 0) ' 9 = tab
style.footertext.text.inserttextcontent(cur4, pageno, 0)
style.footertext.text.insertstring(cur4, " of ", 0)
style.footertext.text.inserttextcontent(cur4, pagect, 0)

The four text inserts are consecutive, as you see. Why has it changed format after the first one?

Edited: Didn't notice pageno and pagect were my own variable names, so I've added their definitions.

Re: Page m of n in footer reverts to default style

PostPosted: Tue Mar 05, 2019 9:39 pm
by JeJe
Have you tried putting

cur4.charfontname = FTR_FONT
cur4.charheight = FTR_SIZE

again after every insert?

Re: Page m of n in footer reverts to default style

PostPosted: Wed Mar 06, 2019 2:52 pm
by Grytpype
Okay, I've now tried that. Actually I put it in front of the second insert (of pageno) and it made that correct and the following "of", but the second variable field was still wrong. So it's the variables that are reverting to the default.

When I looked up how to do the equivalent in MS Word, namely .Fields.Add() with Text of "PAGE" or "NUMPAGES", I saw the example code always included PreserveFormatting:=True. This sounds like exactly what is needed, but in fact it works fine in Word if you leave that out. Is there an equivalent parameter that has been recently added to LO, perhaps?

I have just been warned (on another thread) that my newly installed version is buggy, not stable, so perhaps this is just one of those things. Anyway, it's working now, with inelegantly repeated code.

Re: Page m of n in footer reverts to default style

PostPosted: Wed Mar 06, 2019 2:57 pm
by Villeroy
If you don't understand the concept of templates and styles, you can't use nor program this office suite. And once you know about styles and templates you don't need those dirty macros anymore.

Re: Page m of n in footer reverts to default style

PostPosted: Wed Mar 06, 2019 4:13 pm
by JeJe
Elegance is fine - but if you can hack together something else that acceptably works, then its a waste your time.