How to get to the page number in Asponse word document object?

I need to iterate through the pages in the word document and grab the page number in the footer to do something with it… In this case build a concatenated string using page number and add a barcode at the bottom of the page.

Can you tell me how to iterate through looking for this information. ?
I know Aspose pdf document has the Page property… but Aspose Word doesn’t seem to have it.

How do I loop through the pages of the word documen looking for this ?


Thanks for your inquiry. Please note that Word document is flow document. There is no page concept in Word document. The pages are created on the fly. The page number in the Word document is generated by Page field. Could you please share your input and expected output Word documents here for our reference? We will then provide you more information about your query. (257.5 KB)

Hello Tahir.
Thank you for responding.
The issue here is explained in the screen shot included in the zip file.
We cannot disconnect footer in the docx since we don’t know at run time if the bound data will push document down and add additional pages to the document. So we cannot disconnect footer and provide a hardcoded barcode content control for each page.

I have tried to use the CustomAsposeReplaceEvaluator to replace the text for the barcode I built… but since that replaces all instances of what it finds… Whatever in barcode 2 will overlay barcode 1 in the prior page… making it useless.

Can you provide some guidedance on how we can do this.

FYI… we have license for your Aspose total for .net so we have all your dlls.
I’ve been using AsposeWord to find replace text… and Aspose Barcode to build barcode image.

We also have Aspose PDF…
However, we need to properly construct the Docx document with the right barcode data first before we convert to the end product which is PDF . That part should have no issue. It’s the building of different barcode for each page that share a global footer that presented the problem.

Thank you.


Thanks for sharing the detail. In your case, we suggest you please replace your barcode with “Page {PAGE * MERGEFORMAT} of {NUMPAGES * MERGEFORMAT}” and set its font name as “Free 3 of 9 Extended”. This is the same content in the footer of your document. Hope this helps you.

If you still face the problem, please manually create your expected document using Microsoft Word and attach it here for our reference. We will investigate as to how you want your final output be generated like. We will then provide you more information on this along with code.

Hello again, Tahir

I am attaching a zip of my visual studio solution for you to review.
The template document (NickTest,docx) has only 5 pages… However, when you run the code to build the barcode I end up with 9 pages… and the page number of page 9 says Page 9 of 5. which really is very confusing.

The template uses content control to mark the position of the barcode that needs to be generated.
And when scanned, should show the corresponding page number of where the barcode lives…
However, as you can see in the generated file… if you scan it, all pages currently shows up as page 1.
This is where I need your help. Possibly show me how we can get these proper barcode in each page footer generated correctly.

Thank you.
ps. The solution has referenced dlls in the bin folder… which includes the OpenXML as well as Aspose Word and Aspose Barcode references…

I did not see the zip file that I just uploaed to this thread…
Please let me know if you received it… Not sure if there is a size limitation on the uploaded file…
I am reuploading… This time with empty bin folder… May be the firewall did not allow exe to be included in the zip file.If you still have not received it, I can send you via email … If you don’t want to provide your email address here… please send me an email at and I will send you the zip file. Thank you.

Here is the zip file of my template (NickTest.docx) and the generated output file (testgenerated.docx)
for your (161.2 KB)


Thanks for sharing the detail. Please remove references from the Visual Studio project, ZIP and attach it here for testing. Thanks for your cooperation.

You will have to add the nuget for Document OpenXML sdk and related Aspose Word and Barcode
Thanks. (200.2 KB)


Thanks for sharing the detail. Please note that Aspose.Words mimics the behavior of MS Word. If you insert an image (barcode) in the footer of document using MS Word and convert it to PDF, you will get the same output.

In your case, we suggest you following solution.

  1. Convert the Word document to PDF using Aspose.Words.
  2. Generate the barcode image for each page using Aspose.BarCode.
  3. Insert the barcode image at your desired location of PDF using Aspose.PDF.

Hope this helps you.

Our end product is pdf… However, we also need to be able to produce document in Docx as well.
So we use the docx template … bind the data… then once we have what we need, we convert to pdf.

The solution you suggests is reverse of what we need.
If we generate PDF first… then is there a way for us to convert the PDF back to word docx so we can have either version of the document ?


Thanks for your inquiry. Yes, you can convert PDF to DOCX using Aspose.PDF. Please refer to the following article.
Convert PDF to DOC or DOCX format