Document doc = new Document();
doc.LoadFromFile(inputFile, FileFormat.Docx);
FixedLayoutDocument layoutDoc = new FixedLayoutDocument(doc);
// Access to the line of the first page and print to the console.
FixedLayoutLine line = layoutDoc.Pages[0].Columns[0].Lines[0];
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendLine("Line: " + line.Text);
// With a rendered line, the original paragraph in the document object model can be returned.
Paragraph para = line.Paragraph;
stringBuilder.AppendLine("Paragraph text: " + para.Text);
// Retrieve all the text that appears on the first page in plain text format (including headers and footers).
string pageText = layoutDoc.Pages[0].Text;
stringBuilder.AppendLine(pageText);
// Loop through each page in the document and print the count of the lines appear on each page.
foreach (FixedLayoutPage page in layoutDoc.Pages)
{
LayoutCollection lines = page.GetChildEntities(LayoutElementType.Line, true);
stringBuilder.AppendLine("Page " + page.PageIndex + " has " + lines.Count + " lines.");
}
// This method provides a reverse lookup of layout entities for any given node
// (except runs and nodes in the header and footer).
stringBuilder.AppendLine("The lines of the first paragraph:");
foreach (FixedLayoutLine paragraphLine in layoutDoc.GetLayoutEntitiesOfNode(
((Section)doc.FirstChild).Body.Paragraphs[0]))
{
stringBuilder.AppendLine(paragraphLine.Text.Trim());
stringBuilder.AppendLine(paragraphLine.Rectangle.ToString());
}
File.WriteAllText("page.txt", stringBuilder.ToString());