I'm trying to get all pages of MSWord document via Microsoft.Office.Interop.Word (I'm using C# in VS2012). What I would like to get is List< String > Pages, where index is the number of page. I understand (at least I think so) that there is no direct way to do that. So I came up with something like that:
List<String> Pages = new List<String>();
int NumberOfPreviousPage = -1;
int NumberOfPage = -1;
string InnerText = "";
for (int i = 0; i < Doc.Paragraphs.Count; i++)
{
Paragraph CurrentParagraph = Doc.Paragraphs[i + 1];
InnerText = CurrentParagraph.Range.Text;
NumberOfPage = CurrentParagraph.Range.get_Information(WdInformation.wdActiveEndPageNumber);
if (NumberOfPage == NumberOfPreviousPage)
Pages[Pages.Count - 1] += String.Format("
{0}", InnerText);
else
{
Pages.Add(InnerText);
NumberOfPreviousPage = NumberOfPage;
}
}
But, when algorithm gets to paragraph, which starts on one page and ends on another, it decides that paragraph should be on next page. I want to split this paragraph between pages, but I don't know how to detect where I have to do the split.
See Question&Answers more detail:os