How to calculate the number of lines fitted in a page using aspose

I am using Aspose java to generate the report in doc file. I don’t have an idea in Aspose as how many lines can be limited in a page.

For example , 50 lines of data is available to write and once the page is not sufficient to write all 50 lines then automatically it should move to next page.

Are there any commands in aspose to know currently the cursor is in which line or any way to find the exact number of lines to fit in a page?

Please help me out on this.

Hi Suganya,

Thanks for your inquiry.
Please note that 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. Pages are
created by Microsoft Word on the fly.

Aspose.Words uses our own Rendering Engine to layout documents into pages. 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. Please read about LayoutCollector and
LayoutEnumerator from here:
http://www.aspose.com/docs/display/wordsjava/LayoutCollector+class
http://www.aspose.com/docs/display/wordsjava/LayoutEnumerator+class

In your case, I suggest you please use the LayoutCollector.getStartPageIndex method to get 1-based index of the page where node begins. I suggest you following solution for your scenario.

1) Insert Run node with empty text at the end of document
2) Get the page number of inserted Run node using LayoutCollector.getStartPageIndex
3) Check the page number of last node of document after inserting new contents
4) If the page number of Run node and last node of document is not same, insert the page break at the position of inserted Run node (at step 1).

Hope this helps you. Please let us know if you have any more queries.