I am working on a C # project that will create a Word document using the Word Automation API.
I would like to insert page breaks at certain points in the generated document, and I am currently doing this successfully with the following code:
object pageBreak = WdBreakType.wdPageBreak;
wordApp.Selection.InsertBreak(ref pageBreak);
However, if the document was naturally wrapped on the next page in any case after leaving the room on the previous page, then I really do not want to generate a page break, otherwise I get a blank page.
I would really like to know where the cursor is located, and if it is in the first row and column of the current page, I can safely assume that there is no need to insert a page break.
Is there a way to access the cursor position? Or another solution that will do the same? This seems like a simple requirement, so I apologize in advance if I missed the obvious.
source
share