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

Free Support Forum - aspose.com

Identifying end of page while building the document


I am using Aspose.Words for .Net version 14.6. While building a document, before adding a paragraph i need to identify if the paragraph would fit within the page or not, if not i want to insert a page break and then add the paragraph.
Please let me know if there is a way to achieve the same using Aspose API’s.

Hi Mantu,

Thanks for your inquiry.
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:

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

1) Get the page number of last node of document using LayoutCollector.getStartPageIndex
2) Insert the new Paragraph which you want to insert and get the Paragraph object
3) Get the page number of last Run node of inserted Paragraph. If this Paragraph has only one Run node, please insert a Run node with empty text at the end of this paragraph and get the page number of this new run node.
4) If page number (in first step) is not equal to the page number (get in step 3), please
insert the page break at the position of inserted paragraph.

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

Thanks Tahir for your response. I actually have the paragraph as part of a frame hence it does not go over to the next page. It continues to add the paragraphs within the current page till it becomes invisible. I wanted to know if it is possible to find out if the paragraph added to the frame has reached the lower bounds of the page. If i can know it then i can add a page break before adding the next frame paragraph while building the document.

Hi Mantu,

Thanks for your inquiry. It would be great if you please share following detail for investigation purposes. We will then provide you more information on this along with code.

  • Please attach your input Word document.
  • Please
    attach your target Word document showing the desired behavior. You can
    use Microsoft Word to create your target Word document. I will
    investigate as to how you are expecting your final document be generated

Hi Tahir,

I have attached an image of the problem (see the box in red) i am facing. If you see i need to add specific content to a frame so that it gets displayed on the right of the page. However if there is lot of content to be shown in the frame it gets hidden visually at the end of the page does not flow over to the next page. Before we add the paragraph to the frame is there is a way to identify that paragraph within the frame has reached end of page and if so then add a normal paragraph with page break so that we can move to a new page and then add the frame paragraphs again. Let me know your views.

Hi Mantu,

Thanks for your inquiry. Please manually create your expected Word document using Microsoft Word and attach it here for our reference. We will investigate how you want your final Word output be generated like.

Please also attach your input Word document. We will then provide you more information on this along with code.