-
Notifications
You must be signed in to change notification settings - Fork 547
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get Current Page n #1515
Comments
Hi @adriana-185, The {PAGE} field that your code inserts is working as expected. The problem is that it is not automatically updated. If you right click on the field location in Word's UI, you can select !Update Field and it will show the correct page number. The reason for this is that PAGE or other pagination related fields are calculated at print time by default. Please refer to this article to see the explanation: |
I can add a little more here. What I think you're missing is a w:t or text child element for the fldSimple element or SimpleField object. If you do something like this: run.RunProperties.Append(italic);
run.AppendChild(new Text("Pág: "));
run.AppendChild(new SimpleField(new Text("3")) { Instruction = "PAGE" });
run.AppendChild(new Text("/" + pageCount)); Then at least you will see the placeholder number, in this case "3" next to the "/5" or whatever the page count ends up being. However, it still stands that this will not update automatically. You will have to tell Word to update the field to reflect the current page and not just the placeholder value you added in code. The reason you saw "{PAGE}" is due to a setting in Word that tells it to display the field codes. With your source code, the field was always there, it just didn't have a placeholder text like "3" and Word was displaying the field codenames. To toggle this option, go to Hopefully that will help you. |
@adriana-185 are you ok to close this? |
I have a part of a code that opens a docx document and edits it, it adds several things and one of those is the page number you're currently in, so it should look like "Pag: 1/5". Until last week it worked just fine, but today I noticed that it no longer displays the current page number but displays in its' place "{PAGE}", ending up with "Pag:{PAGE}/5". I'm using this code on a project and both the testing code and the server code have this problem (and I haven't updated the server code in more than a month.
The following code is how it gets the current page number, which worked before:
run.AppendChild(new SimpleField() { Instruction = "PAGE" });
The full part that the code is in:
The text was updated successfully, but these errors were encountered: