Following code always returns 1, but the shape is actually in page 3:
using System;
using System.Collections.Generic;
using System.Text;
using Aspose.Words;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
Aspose.Words.Document doc = new Aspose.Words.Document(@"C:\temp\test3\doc1.docx");
PageFinder.PageNumberFinder pf = new PageFinder.PageNumberFinder(doc);
Node n = doc.GetChildNodes(NodeType.Shape, true)[0];
// GetPage() always return 1
int p = pf.GetPage(doc.ChildNodes[0]);
}
}
}
Hello
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)[0];
Console.WriteLine(GetNodePageNumber(n));
private int GetNodePageNumber(Node node)
{
// Create a DocumentBuilder and move it to the node.
DocumentBuilder builder = new DocumentBuilder((Document) node.Document);
builder.MoveTo(node);
// Insert a PAGE field and update it.
Field page = builder.InsertField("PAGE");
builder.Document.UpdatePageLayout();
page.Update();
int pageNumber = Int32.Parse(page.Result);
// Remove PAGE field.
page.Remove();
return pageNumber;
}
Hello
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.
Best regards,