Page 1 of 1

Adding a automatic page numbering to a footer

Posted: Sun Sep 10, 2017 1:46 pm
by Michel Huybrechts
Using the examples from the samples I see how to add headers and footers to a page. I also figured out how to add tabs and figures. However, I can't find a way to add an automatic page numbering. The documentation does not explain this either.

How to add "page <#>" in a footer such that MSWord automatically fills in the <#> for each page?

Thank you

Re: Adding a automatic page numbering to a footer

Posted: Sun Sep 10, 2017 3:55 pm
by larsa
Hello

You uses field codes for this.

Example:

Code: Select all

  DOCX.Editor.MainDoc.Headers.AddDefault;
  DOCX.Editor.MainDoc.Headers.Default_.Paras[0].AppendField('1','PAGE');
'1' is the default value. 'PAGE' is the field code

Re: Adding a automatic page numbering to a footer

Posted: Mon Sep 11, 2017 12:17 pm
by Michel Huybrechts
Thank you, this works perfectly

Re: Adding a automatic page numbering to a footer

Posted: Tue Apr 12, 2022 7:48 pm
by DiBase
I tried the code (with TDOCXReadWriteVcl 2.00.49) in a this modified version:

Code: Select all

  DOCX.Editor.Footers.AddDefault;
  DOCX.Editor.Footers.Default_.Paras[0].PAPX.Alignment := axptaCenter;
  DOCX.Editor.Footers.Default_.Paras[0].AppendPlainText( ' - ' );
  DOCX.Editor.Footers.Default_.Paras[0].AppendField('1','PAGE');
  DOCX.Editor.Footers.Default_.Paras[0].AppendPlainText( ' - ' );
Two issues with that:
  1. the last hyphen is not visible in Word (.docx export)
  2. in preview and pdf export only the default page number is visible (highlighted in gray)
Any solution for both?

- Dirk

Re: Adding a automatic page numbering to a footer

Posted: Tue May 17, 2022 8:17 am
by Vinski
Hi,

I can help you with your first problem, if it is still relevant:
Instead of

Code: Select all

  DOCX.Editor.Footers.AddDefault;
  DOCX.Editor.Footers.Default_.Paras[0].PAPX.Alignment := axptaCenter;
  DOCX.Editor.Footers.Default_.Paras[0].AppendPlainText( ' - ' );
  DOCX.Editor.Footers.Default_.Paras[0].AppendField('1','PAGE');
  DOCX.Editor.Footers.Default_.Paras[0].AppendPlainText( ' - ' );
try

Code: Select all

  DOCX.Editor.Footers.AddDefault;
  DOCX.Editor.Footers.Default_.Paras[0].PAPX.Alignment := axptaCenter;
  DOCX.Editor.Footers.Default_.Paras[0].AppendPlainText( ' - ' );
  DOCX.Editor.Footers.Default_.Paras[0].AppendField('1','PAGE');
  DOCX.Editor.Footers.Default_.Paras[0].AppendFormattedText( ' - ' );
changing the last plain text to formatted text. That is what did the trick for me.

Re: Adding a automatic page numbering to a footer

Posted: Tue Aug 02, 2022 5:58 pm
by DiBase
Hi Vinski,

thank you for your hint, but I solved it by adding two lines in the source code (function TAXWLogPara.AppendPlainText).

The second issue could also solved in the source code.
I changed initialization of FShowFields from True to False (in AXWGDIText.pas: TAXWTextPrint.Create).

- Dirk