Thank you for your time.
I can not get the right page count from layoutDoc.Pages.Count with 11.docx file from the sample code from the offline samples pack.
When the page count of 11.docx file not more than 5 it works fine, but fail when the page count of 11.docx file is more than 5.
There is something wrong when I load a BP-PJM .doc file with the same code. Error: ArgumentOutOfRangeExcepti occur in LayoutEntities.cs, Line 281.
------>>>>
My sample code list below. And please pay your attention to the attachment for test.
static void Main(string[] args)
{
#region
// //// set license
// Aspose.Words.License license = new Aspose.Words.License();
//
// // This line attempts to set a license from several locations relative to the executable and Aspose.Words.dll.
// // You can also use the additional overload to load a license from a stream, this is useful for instance when the
// // license is stored as an embedded resource
// try
// {
// license.SetLicense("Aspose.Words.lic");
// }
//
// catch (Exception e)
// {
// // We do not ship any license with this example, visit the Aspose site to obtain either a temporary or permanent license.
// Console.WriteLine("There was an error setting the license: " + e.Message);
// }
#endregion
string dataDir = Path.GetFullPath("../../Data/");
//Document doc = new Document(dataDir + "TestFile.docx");
Document doc = new Document(dataDir + "11.docx");
// This sample introduces the RenderedDocument class and other related classes which provide an API wrapper for
// the LayoutEnumerator. This allows you to access the layout entities of a document using a DOM style API.
// Create a new RenderedDocument class from a Document object.
RenderedDocument layoutDoc = new RenderedDocument(doc);
// The following examples demonstrate how to use the wrapper API.
// This snippet returns the third line of the first page and prints the line of text to the console.
RenderedLine line = layoutDoc.Pages[0].Columns[0].Lines[2];
Console.WriteLine("Line: " + line.Text);
// With a rendered line the original paragraph in the document object model can be returned.
Paragraph para = line.Paragraph;
Console.WriteLine("Paragraph text: " + para.Range.Text);
// Retrieve all the text that appears of the first page in plain text format (including headers and footers).
string pageText = layoutDoc.Pages[0].Text;
Console.WriteLine();
// Loop through each page in the document and print how many lines appear on each page.
foreach (RenderedPage page in layoutDoc.Pages)
{
LayoutCollection lines = page.GetChildEntities(LayoutEntityType.Line, true);
Console.WriteLine("Page {0} has {1} lines.", page.PageIndex, lines.Count);
}
// This method provides a reverse lookup of layout entities for any given node (with the exception of runs and nodes in the
// header and footer).
Console.WriteLine();
Console.WriteLine("The lines of the second paragraph:");
foreach (RenderedLine paragraphLine in layoutDoc.GetLayoutEntitiesOfNode(doc.FirstSection.Body.Paragraphs[1]))
{
Console.WriteLine(string.Format("\"{0}\"", paragraphLine.Text.Trim()));
Console.WriteLine(paragraphLine.Rectangle.ToString());
Console.WriteLine();
}
}