We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Page Number of Paragraph

Hi,


How can I get page number of Paragraph object? I know that a paragraph may spread out multiple pages. Getting all pages numbers containing the paragraph or just starting page is sufficient.

Thanks,

Hi Huseyin,


Thanks for your inquiry. You will be able to find out on which page a particular document node (e.g. Paragraph) is located by using the LayoutCollector.GetStartPageIndex, LayoutCollector.GetEndPageIndex and LayoutCollector.GetNumPagesSpanned methods. These methods automatically build page layout model of the document and update fields if required. You can use the following sample code to determine the Page number of a Paragraph:

Document doc = new Document(@“C:\temp\in.docx”);

LayoutCollector lc = new LayoutCollector(doc);<o:p></o:p>

Paragraph target = null;<o:p></o:p>

foreach (Paragraph para in doc.GetChildNodes(NodeType.Paragraph, true))<o:p></o:p>

{<o:p></o:p>

// Get the paragraph you want to find the Page Number of<o:p></o:p>

target = para;<o:p></o:p>

}<o:p></o:p>

if (target != null)<o:p></o:p>

Console.WriteLine(lc.GetStartPageIndex(target));<o:p></o:p>


I hope, this helps.

Best regards,

Hi Awais,


It was what i’ve required.

Thank you,