Page 1 of 1

[Solved] Missing Page Number

PostPosted: Thu Aug 17, 2017 1:56 am
by Whekenui
I wish to write a report with page numbers in a footer. The page number is missing on the first page but appears correctly in all subsequent pages.

Most likely some kind of document initialisation problem but nothing I have done appears to help. Do I need to explictly start a service for page numbering perhaps?

The program below is based on Bernard Marcelly's TestOpen program written for Delphi.

Code: Select all   Expand viewCollapse view
// Initialisation

procedure ConnectOpenOffice;
  if IsOpenOfficeConnected then exit;
  Screen.Cursor:= crHourglass;      Application.ProcessMessages;
    OpenOffice:= CreateOleObject('');
    if isNullEmpty(OpenOffice) then    Raise EOOoError.Create(OOo_connectKO);
    StarDesktop:=       CreateUnoService('');
    disp:=              CreateUnoService('');
    OOoIntrospection:=  CreateUnoService('');
    OOoReflection:=     CreateUnoService('');
    Screen.Cursor:= crDefault;

// Program body

    v := VarArrayCreate ([0, -1], varVariant);

    MyDoc := StarDesktop.loadComponentFromURL('private:factory/swriter', '_blank', 0, v);
    MyText:= MyDoc.Text;
    MyCursor:= MyText.createTextCursor;

{       Sort out the page styles and turn the header and footer on.     }

    MyPageStyles := MyDoc.StyleFamilies.getByName ('PageStyles');
    MyStdPage := MyPageStyles.getByName ('Standard');
    MyStdPage.FooterIsOn := true;
    MyStdPage.FooterHeight := 1000;

{       Write the footer text.                                          }

    MyFooter := MyStdPage.FooterText;
    MyFooterText := MyFooter.Text;
    MyFooterCursor := MyFooterText.createTextCursor;
    MyFooterCursor.breakType := _styleBreakTypeNONE;
    MyFooterCursor.charHeight := 10;
    MyFooterCursor.charWeight := _awtFontWeightNORMAL;
    MyFooterCursor.charFontName := 'Verdana';

    MyPageNumber := MyDoc.createInstance ('');
    MyPageNumber.NumberingType := _styleNumberingTypeARABIC;
    MyFooterText.insertString (MyFooterCursor, 'PPPPage ', FALSE);
    MyFooterText.insertTextContent (MyFooterCursor, MyPageNumber, FALSE);

{       Generate a couple of pages of data.                             }

    MyText.insertString(MyCursor, OOoMess111, false);
    MyText.insertControlCharacter (MyCursor, _textControlCharacterPARAGRAPH_BREAK, false);

    for i := 1 to 70 do
        MyText.insertString(MyCursor, 'xxxxxxxx' + Tab + 'yy' + Tab + 'zzzzzzzzzz' + Tab + 'ASASA' + Tab + '66612.34566', false);
        MyText.insertControlCharacter (MyCursor, _textControlCharacterPARAGRAPH_BREAK, false);

The footer on the first page contains PPPPage..
The footer on the second page contains PPPPage 2

TIA, any thoughts will be most gratefully received.

Re: Missing Page Number

PostPosted: Thu Aug 17, 2017 2:47 am
It would be very helpful if you uploaded a copy of the document. There is an Upload Attachment tab just below the window where you type a response after clicking Post Reply.

Re: Missing Page Number

PostPosted: Thu Aug 17, 2017 3:22 am
by Whekenui
Thanks for your suggestion. Here is the document produced. Can I draw your attention to the 'page number' at the bottom of page 1. PPPPage is followed by 2 dots (after turning on the display of non printing characters). Its as if its trying to print the page number but not quite making it.

Re: Missing Page Number

PostPosted: Thu Aug 17, 2017 5:06 am
If you turn on the menu item View -> Field Names, you will see that you inserted a field that of the type Previous Page. If you manually insert a Page Number field, it shows the Field Name Page Number. I think you have to set the NumberingType of the field you insert to the ENUM value CURRENT, as shown here.
I have no idea why the second page shows a 2 when the NumberingType is set to Previous.

Re: Missing Page Number

PostPosted: Thu Aug 17, 2017 7:16 am
by Whekenui
You're quite right about the previous page. I changed the program a bit to include the 3rd line below

MyPageNumber := MyDoc.createInstance ('');
MyPageNumber.NumberingType := _styleNumberingTypeARABIC;
MyPageNumber.PageNumberType := _textPageNumberTypeCURRENT;

This produced an error 'EOleError Method PageNumberType not supported by automation object'

I also tried setting PageNumberType on MyDoc and MyFooter with the same results.

I also tried
v := MyPageNumber.getPropertyValue('PageNumberType');
ShowMessage (VarToStr (v));
Not surprisingly this produced an UnknownPropertyException

So, maybe the property now has a new name? While I've been poking through the documentation I think I saw a reference
to something that would display the properties and methods of an object but I've lost sight of this. Do you by any chance know
what these calls might be?

Thanks for taking an interest.

Re: Missing Page Number

PostPosted: Thu Aug 17, 2017 2:25 pm
The best way to look at the properties and methods of an object is to use an object inspection tool, either XRay or MRI. Search for openoffice extensions with one of those names.
I will take a look later today (US time) at inserting a page number with a macro.

Re: Missing Page Number

PostPosted: Fri Aug 18, 2017 2:59 am
by Whekenui
I've made sure I've got the latest version installed, I've tried inserting text into the page before creating the footer, but to no avail.

I found the tools I mentioned at ... /UNO_Tools but they didn't work.

I'm starting to look at MRI but I'll have to find out how this works first. I'm also going to try writing a footer in the form Page n of ~
and then doing a global replace of the ~ with the total number of pages.

Any suggestions appreciated.

Re: Missing Page Number

PostPosted: Fri Aug 18, 2017 7:00 am
I translated your code into Basic and got the page numbering to work by setting the subtype property of the PageNumber service.
Code: Select all   Expand viewCollapse view
    MyPageNumber = MyDoc.createInstance ("")
    MyPageNumber.subType =
    MyPageNumber.NumberingType =
    MyFooterText.insertString (MyFooterCursor, "PPPPage ", FALSE)
    MyFooterText.insertTextContent (MyFooterCursor, MyPageNumber, FALSE)

Re: Missing Page Number

PostPosted: Sun Aug 20, 2017 4:50 am
by Whekenui
I've tried that back in Delphi where it also works!

This solves a big problem for me, I'm extremely grateful for your help :bravo:

I will mark the issue as solved.