Textbox at every page

It seems that as a DOM flow document, Aspose.Words does not truly possess knowledge on the number of pages in a document? We have a requirement to place a Textbox (Shape?) exactly at an absolute position on every page. This is to insert a printing serial number before the docs are printed.
I do not see anything immediate from the API that can easily achieve this, as the Shape object of a manually positioned Textbox ends up as a child in whatever paragraph object is there. Is it possible in the first place? thanks


Thanks for your inquiry. You can easily achieve this by inserting your textbox into the document header. You can use the approach suggested in the following article:
Best regards.

Hey Alexey, the content (numbers) inserted into the textBox for each page is not merely a page number, it is a batch sequence number that comes from application logic. I do not think inserting a common watermark textBox in the Header will allow us to make it unique per page.


Thank you for additional information. MS Word document is flow document and does not contain any information about its layout into lines and pages. So there is no way to determine where page starts or ends. In Aspose.Words we are using our own Rendering Engine to layout document into pages. The Rendering Engine is using for converting to PDF, XPS and Printing. But, unfortunately, currently, there is no public API to determine where pages start/end.
The only way to work the problem around, I can suggest you at the moment is converting your document to PDF, the insert your textboxes on each page using Aspose.Pdf.Kit and then printing the resulting PDF.
Best regards.

Hi Aaron,
This is actually possible using what’s currently available in the Public API for Aspose.Words. It does take a bit of extra programming though. I have written a quick implementation as an example for you to try. It should work properly for most documents although it has not been thoroughly tested. Attached is the class containing the code. You can call it in your document like this:

Document doc = new Document("Document.doc");

PageNumberFinder finder = new PageNumberFinder(doc);
for (int page = 1; page <= doc.PageCount; page++)
    ArrayList pageNodes = pageFinder.RetrieveAllNodesOnPage(page, page, NodeType.Paragraph);
    // Insert a specific text box on each page at absolute position using this paragraph
    AddTextBoxToPage(pageNodes, page);

doc.Save("Document Out.doc");

Please ask if you have any further queries.

Hello Adam,
although i haven’t fully understood how the mechanism works, i’ve tested it on a sample test document and it does appear to place an absolute textbox on each page. need to play around with it more to realise its effect.

Hi Aaron,
It’s great that it works. I will give you a quick overview of the algorthim below which will hopefully give you a better understanding about what it’s doing. It’s simply inserting fields around certain nodes in the documents and updating then parsing the results. It then uses these page results to calculate the page numbers of all the other nodes in the document.

The issues you have found earlier (filed as WORDSNET-2978) have been fixed in this .NET update and this Java update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.