Following code always returns 1, but the shape is actually in page 3:
Thanks for your request. Please try using the following simple code:
Document doc = new Document("C:\\Temp\\Doc1.docx");
Node n = doc.GetChildNodes(NodeType.Shape, true);
private int GetNodePageNumber(Node node)
// Create a DocumentBuilder and move it to the node.
DocumentBuilder builder = new DocumentBuilder((Document)node.Document);
// Insert a PAGE field and update it.
Field page = builder.InsertField("PAGE");
int pageNumber = Int32.Parse(page.Result);
// Remove PAGE field.
Hope this helps.
You code does return correct page number “3”. I just wonder what is the impact to use this code. Is it could be slow? Thanks.
Thanks for your inquiry. PageFinder class, which you used previously, works in the same way.
Let me explain, MS Word document is flow document and does not contain any information about its layout into lines and pages. Therefore, technically there is no “Page” concept in Word document.
Aspose.Words uses our own Rendering Engine to layout documents into pages (that is why you need to call UpdatePageLayout method). But we have plans to expose layout information. Your request has been linked to the appropriate issue. You will be notified as soon as this feature is supported.