Search code examples
c#office-interopword-interop

How to identify last Paragraph of each page in a Word document using Word Interop?


I am creating a C# program which makes some automatic changes to several Word documents. One of the requirements is to move the headings to the next page when the following paragraph is in the next page.

The image below exemplify my description:

enter image description here

At the beginning i did try to identify the headings in the Paragraphs collection (it was possible using info about the style of the headings) because I thought it will be possible to get information about its location in the current page. After some tries, I think that method will not succeed.

I think the key point of this is:

How to identify if a heading is in the last line of a page. However, I do not know if that is feasible.

I will appreciate any suggestion about how to achieve this goal.

Thanks


Solution

  • You don't need code to keep the heading with the paragraph text. You can achieve this setting the heading paragraph property 'keep with next'.