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

Free Support Forum - aspose.com

Search Text and Show the page no

Hi,

My Document is having String called hello at Page 1, Page 3. My o/p should be like this.

Hello found at Page 1 Hello found at Page 3.

I tried to do but i failed.

I was able to Highlight that Text but failed to get page number. Is there any way to find that on which page no my searchstring is.

Note : 1)There are one blank Page Page 1. 2)There are No paragraphs at the end and starting of pages.

Awaiting reply.


Hi Crimson,


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. Please refer to the following classes:

LayoutCollector
LayoutEnumerator

Hope, this helps.

Best regards,

Hi,

Thanks for the suggestion. Can you give example code for the same or how to use given options

Hi Crimson,


Thanks for your inquiry. Please try using the following Java code:

Document doc = new Document(getMyDir() + “input.docx”);
LayoutCollector layout = new LayoutCollector(doc);
for(Run run : (Iterable)doc.getChildNodes(NodeType.RUN, true)){
if (run.getText().contains(“Hello”)){
System.out.println(" Hello found at page " + layout.getStartPageIndex(run));
}
}

Hope, this helps.

Best regards,

Hi,


Thanks for the code…! It works…