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
Adding a automatic page numbering to a footer
-
- Posts: 3
- Joined: Sun Sep 10, 2017 1:30 pm
Re: Adding a automatic page numbering to a footer
Hello
You uses field codes for this.
Example:
'1' is the default value. 'PAGE' is the field code
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');
Lars Arvidsson, Axolot Data
-
- Posts: 3
- Joined: Sun Sep 10, 2017 1:30 pm
Re: Adding a automatic page numbering to a footer
Thank you, this works perfectly
Re: Adding a automatic page numbering to a footer
I tried the code (with TDOCXReadWriteVcl 2.00.49) in a this modified version:
Two issues with that:
- Dirk
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( ' - ' );
- the last hyphen is not visible in Word (.docx export)
- in preview and pdf export only the default page number is visible (highlighted in gray)
- Dirk
Re: Adding a automatic page numbering to a footer
Hi,
I can help you with your first problem, if it is still relevant:
Instead of
try
changing the last plain text to formatted text. That is what did the trick for me.
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( ' - ' );
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( ' - ' );
Re: Adding a automatic page numbering to a footer
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
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