I am working with the DOM structure and I am using your lib Aspose Words.
Our Word document (attached at this message) has a complex headerfooter : several paragraphs, table, in some case images, fields, …
The question is: how can we read the structure of this headerfooter. Is it possible to get the list of nodes inside the headerfooter? How can we recover the tree of nodes witch is into this headerfooter ?
Thanks for your inquiry. Please use HeaderFooter.ChildNodes property to get all immediate child nodes of this node.
I suggest you please check “document_explorer” example project in Aspose.Words for Java examples repository at GitHub. Hope this helps you. Please let us know if you have any more queries.
Thanks for your reply.
Another question, is it possible to display the page numbers in a DOM?
That is to say, I want to read the DOM of my document. And I want to display the node and for each page the number…
Thanks for your inquiry. The Aspose.Words.Layout namespace provides classes that allow to access information such as on what page and where on a page particular document elements are positioned, when the document is formatted into pages.
When you create a LayoutCollector and specify a Document document object to attach to, the collector will record mapping of document nodes to layout objects when the document is formatted into pages.
You will be able to find out on which page a particular document node (e.g. run, paragraph or table cell) is located by using the getStartPageIndex, getEndPageIndex and getNumPagesSpanned methods. These methods automatically build page layout model of the document and update fields if required.
In your case, I suggest you please use LayoutCollector.getStartPageIndex method. This method gets 1-based index of the page where node begins. Returns 0 if node cannot be mapped to a page.
Thanks for your answer. Have you got some examples which use those methods?
Because I tried to add those methods in my code, however, I have a java.lang.NullPointerException error. So I don’t know where is my issue…
Thanks for your inquiry.
Please check following code example for your kind reference. Hope this helps you. Please let us know if you have any more queries.
Document doc = new Document(MyDir + "Melody.docx");
LayoutCollector layoutCollector = new LayoutCollector(doc);
for (Section section : doc.getSections())
for (Node node : (Iterable)section.getBody().getChildNodes(NodeType.ANY, true))
System.out.println(Node.nodeTypeToString(node.getNodeType()) + " Page number : " + layoutCollector.getStartPageIndex(node));