I tried to detect Page Number only via TextCursor, because Visible Cursor didn’t follow sufficiently quickly the TextCursor when I opened the document as hidden and set .lockControllers → and put a lot of formatted text and images via macro to document → Visible Cursor was too slow sometimes and returned bad page number (for example returned the number of previous page twice, instead of previous page and actual page).
The “hack” is put some object that has the property for Page Number to the TextCursor and anchor it To Page, then get the Page Number of one and delete one.
Sub pageForTextCursor
dim oDoc as object, oCur as object, oShape as object, oSize as new com.sun.star.awt.Size, iPage&
oDoc=ThisComponent
oCur=oDoc.Text.createTextCursor
oCur.goToEnd(false) 'put cursor to position
rem insert Shape with zero size Anchored to Page to TextCursor
with oSize 'for example you can set the size 10x10 for testing
.Width=0
.Height=0
end with
oShape=oDoc.createInstance("com.sun.star.drawing.PluginShape") 'it is undemanding object
with oShape
.TextWrap=1
.AnchorType=4 'at first Achor to Character (because .insertTextContent ignores Anchor to Page)
.Size=oSize
.AllowOverlap=true
.Opaque=true
end with
oDoc.Text.insertTextContent(oCur, oShape, false) 'insert to TextCursor
oShape.AnchorType=2 'Anchor to Page
iPage=oShape.AnchorPageNo 'get the Page number
oDoc.DrawPage.remove(oShape) 'delete Shape
msgbox iPage
End Sub