[Solved] Missing Page Number

Java, C++, C#, Delphi, ??? - Using the UNO bridges

[Solved] Missing Page Number

Postby Whekenui » Thu Aug 17, 2017 1:56 am

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;
begin
  if IsOpenOfficeConnected then exit;
  Screen.Cursor:= crHourglass;      Application.ProcessMessages;
  try
    OpenOffice:= CreateOleObject('com.sun.star.ServiceManager');
    if isNullEmpty(OpenOffice) then    Raise EOOoError.Create(OOo_connectKO);
    StarDesktop:=       CreateUnoService('com.sun.star.frame.Desktop');
    disp:=              CreateUnoService('com.sun.star.frame.DispatchHelper');
    OOoIntrospection:=  CreateUnoService('com.sun.star.beans.Introspection');
    OOoReflection:=     CreateUnoService('com.sun.star.reflection.CoreReflection');
  finally
    Screen.Cursor:= crDefault;
  end;
end;

// 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 ('com.sun.star.text.TextField.PageNumber');
    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
    begin
        MyText.insertString(MyCursor, 'xxxxxxxx' + Tab + 'yy' + Tab + 'zzzzzzzzzz' + Tab + 'ASASA' + Tab + '66612.34566', false);
        MyText.insertControlCharacter (MyCursor, _textControlCharacterPARAGRAPH_BREAK, false);
    end;

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.
Last edited by Whekenui on Sun Aug 20, 2017 4:53 am, edited 2 times in total.
Open Office 4.1.0

Windows 10 Pro 10.0.15063 Build 15063
Whekenui
 
Posts: 5
Joined: Thu Aug 17, 2017 1:28 am

Re: Missing Page Number

Postby FJCC » 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.
Windows 10 and Linux Mint, since 2017
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
FJCC
Moderator
 
Posts: 7087
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Missing Page Number

Postby Whekenui » Thu Aug 17, 2017 3:22 am

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.
Attachments
test.odt
(10.25 KiB) Downloaded 83 times
Open Office 4.1.0

Windows 10 Pro 10.0.15063 Build 15063
Whekenui
 
Posts: 5
Joined: Thu Aug 17, 2017 1:28 am

Re: Missing Page Number

Postby FJCC » 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.
Windows 10 and Linux Mint, since 2017
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
FJCC
Moderator
 
Posts: 7087
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Missing Page Number

Postby Whekenui » Thu Aug 17, 2017 7:16 am

You're quite right about the previous page. I changed the program a bit to include the 3rd line below

MyPageNumber := MyDoc.createInstance ('com.sun.star.text.TextField.PageNumber');
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.
Open Office 4.1.0

Windows 10 Pro 10.0.15063 Build 15063
Whekenui
 
Posts: 5
Joined: Thu Aug 17, 2017 1:28 am

Re: Missing Page Number

Postby FJCC » 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.
Windows 10 and Linux Mint, since 2017
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
FJCC
Moderator
 
Posts: 7087
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Missing Page Number

Postby Whekenui » Fri Aug 18, 2017 2:59 am

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 https://wiki.openoffice.org/wiki/Docume ... /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.
Open Office 4.1.0

Windows 10 Pro 10.0.15063 Build 15063
Whekenui
 
Posts: 5
Joined: Thu Aug 17, 2017 1:28 am

Re: Missing Page Number

Postby FJCC » 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 ("com.sun.star.text.TextField.PageNumber")
    MyPageNumber.subType = com.sun.star.text.PageNumberType.CURRENT
    MyPageNumber.NumberingType = com.sun.star.style.NumberingType.ARABIC
    MyFooterText.insertString (MyFooterCursor, "PPPPage ", FALSE)
    MyFooterText.insertTextContent (MyFooterCursor, MyPageNumber, FALSE)
Windows 10 and Linux Mint, since 2017
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
FJCC
Moderator
 
Posts: 7087
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Missing Page Number

Postby Whekenui » Sun Aug 20, 2017 4:50 am

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.
Open Office 4.1.0

Windows 10 Pro 10.0.15063 Build 15063
Whekenui
 
Posts: 5
Joined: Thu Aug 17, 2017 1:28 am


Return to External Programs

Who is online

Users browsing this forum: No registered users and 3 guests