We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Update the page number on each page of a document after inserting another one into it

Hello,

I have read many posts in the forum to find the answer and solve my problem, I tried some recipies, but I have not found anything that gives a good result for my situation.

Before explanation, just keep in mind that we work only in memory, we get BLOB on Oracle Database for each document. Work them with Aspose Words always in memory and save the final document in PDF format in another BLOB in the database (we do not put anything on disk ).

Here is the situation:
I have a litte document Word containing Header (contining Page field and NumPages field)
and a footer containing static text and a body containing only a mergefield {Mergefield sect_sec_2} that is like a bookmark ton insert another document containing many pages of text.
In this case it contains 461 pages, another time it may contains more or less of pages.

So, using the breakpoints in debugging mode in C# :
I look Aspose detail of the first document, I see page 0001 of 000001.
Do a Document.UpdateFields() to put {Mergefield sect_sec_2} into <<sect_sec_2>>
I let go the treatment to insert the second document in place of <<sect_sec_2>>
I look again in Aspose detail and I see page 0001 of 000001.
I execute the research of NUMPAGES field and update it ==> Now I see page 0001 of 000461
But I cannot see each one of the values of PAGE field (that will appear on each page).
If I do a field.Update() on that field it turns to 461 (the number of the last page) and write it on all pages from the first to the last one.
I cannot do another document.UpdateFields() because I lose all the text of the second document inserted and I return to {Mergefield sect_sec_2} who has the result <<sect_sec_2>>.
I cannot use UnlinkFields because the PageField disappears.
I think there is a simple way but I just cannot find it in all the posts.

Hope that you understand my explanation.
Can you please help me
Thank’s a lot!



Hi there,

Thanks for your inquiry. To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word documents.
  • Please attach the output Word file that shows the undesired behavior.
  • Please attach the expected output Word file that shows the desired behavior.
  • Please create a standalone console application (source code without compilation errors) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we'll start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip them and Click 'Reply' button that will bring you to the 'reply page' and there at the bottom you can include any attachments with that post by clicking the 'Add/Update' button.

Hello Tahir,


By preparing the code for the console application I realized that I had deleted a line in my code.
Just by adding the line for UpdatePageLayout() and everyting has become OK.
Thank you very much and I’m sorry to have bothered you.

Diane
Hi Diane,

It is nice to hear from you that your problem has been resolved. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.