We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

LayoutCollector incorrectly calculates page numbers

Dear Sir or Madam,


I use Aspose.Words to produce a report. The report has a wrapper table in the cell of this wrapper I insert my real data. My task is to find out the first row in the table moved to the next page. So having added to the output document a table under the question I run the code I grabbed from your website:
if (table.NodeId == “NaaNoteTbl0”)
{
LayoutCollector layoutCollector = new LayoutCollector(mOutputDocument);
foreach (Aspose.Words.Node node in contentWrapCell.GetChildNodes(NodeType.Any, true))
{
System.Diagnostics.Debug.WriteLine(" --------- ");
System.Diagnostics.Debug.WriteLine("NodeType: " + Aspose.Words.Node.NodeTypeToString(node.NodeType));
System.Diagnostics.Debug.WriteLine(“Text: “” + node.ToString(SaveFormat.Text).Trim() + “””);
System.Diagnostics.Debug.WriteLine(“Page Start: " + layoutCollector.GetStartPageIndex(node));
System.Diagnostics.Debug.WriteLine(“Page End: " + layoutCollector.GetEndPageIndex(node));
System.Diagnostics.Debug.WriteLine(” --------- “);
System.Diagnostics.Debug.WriteLine(””);
}
}
Unfortunately this code produces the wrong result. If you have a look in attached word document and search for Note 33. Non-current assets - property, plant and equipment you’ll see that it is located on pages 28 and 29 of the document. Meanwhile according to output it is located on pages 29-31. Needless to say that the pages for individual rows are incorrect. Could you please tell me if I do something wrong and how I can get the correct data? Once again the task is to find the first row to be moved on the next page so probably there is any other way/API to do it?

Regards,
Alex

Any update on this issue?

Hi Alex,


Thanks for your inquiry and sorry for the delayed response. There are only two occurrences of Paragraphs that start with text “Note 33” in your document. The first Paragraph is located at the start of 28th page inside the first cell of the wrapping table; you can get start/end page index of this Paragraph, it’s parent Cell and Row by using the following code.

Document doc = new
Document(@“C:\Temp\Magic
1500 Limited-Annual Report-30062012.docx”
);

LayoutCollector layoutCollector = new LayoutCollector(doc);

DocumentBuilder builder = new DocumentBuilder();

NodeCollection paragraphs = doc.GetChildNodes(NodeType.Paragraph, true);

foreach (Paragraph para in paragraphs)

{

if (para.ToString(SaveFormat.Text).StartsWith("Note 33"))

{

Table tab = (Table)para.GetAncestor(NodeType.Table);

if (tab != null)

{

// Get statistics of Paragraph contained inside wrapper Table

builder.Writeln(" --------- Paragraph ---------");

builder.Writeln("NodeType: " + Aspose.Words.Node.NodeTypeToString(para.NodeType));

builder.Writeln("Page Start: " + layoutCollector.GetStartPageIndex(para));

builder.Writeln("Page End: " + layoutCollector.GetEndPageIndex(para));

builder.Writeln("");

builder.Writeln(" --------- Cell ---------");

builder.Writeln("NodeType: " + Aspose.Words.Node.NodeTypeToString(para.ParentNode.NodeType));

builder.Writeln("Page Start: " + layoutCollector.GetStartPageIndex(para.ParentNode));

builder.Writeln("Page End: " + layoutCollector.GetEndPageIndex(para.ParentNode));

builder.Writeln("");

builder.Writeln(" --------- Row ---------");

builder.Writeln("NodeType: " + Aspose.Words.Node.NodeTypeToString(para.ParentNode.ParentNode.NodeType));

builder.Writeln("Page Start: " + layoutCollector.GetStartPageIndex(para.ParentNode.ParentNode));

builder.Writeln("Page End: " + layoutCollector.GetEndPageIndex(para.ParentNode.ParentNode));

}

else

{

// Get statistics of Paragraph contained inside primary header of 63th section

}

}

}

builder.Document.Save(@"C:\Temp\out.docx");


The reason why Cell/Row has different EndPageIndex is because they span over two pages but the whole Paragraph remains on a single page. I hope, this clarifies the correctness of Aspose.Words.

The other Paragraph is actually not contained inside the wrapper Table instead it is placed inside the HeaderPrimary of 63th Section.

Best regards,

Hi Awais,


I am afraid I wasn’t able to explain the issue properly. It is not related to paragraph location. I mentioned the paragraph in order to make it easy for you (support) to find the table I have the grieve with. If you look on the table in Note 33. Non-current assets… you’ll see that it is a long table located on few pages. I tried to get the start and end row for each row in this table and flush it into a text file (it is attached). Here are some data from this file with my comments in bold:
NodeType: Cell
Text: "Land - at directors valuation"
Page Start: 29
Page End: 29
---------
while in reality this cell is located on page 28 of the document.

NodeType: Cell
Text: "Leasehold improvements - at directors valuation"
Page Start: 30
Page End: 30

while this cell is located on the same page 28 as a previous cell.

---------
NodeType: Cell
Text: "Motor vehicles under lease"
Page Start: 30
Page End: 30
---------

---------
NodeType: Cell
Text: "Less: Accumulated depreciation"
Page Start: 30
Page End: 30
---------
which implies that these 2 cells are on the same page while in fact they are on the different pages and so on.

Regards,
Alex

Hi Alex,


Thanks for the additional information. I am afraid, I was still unable to reproduce this issue on my side. Please create a simple console project that helps me reproduce the same problem on my end and attach it here for testing. As soon as you send this application to me, I’ll start investigation into your issue. Thanks for your cooperation.

Best regards,

Hi Awais,


Thank you for your reply I figured out the issue.

Regards,
Alex

Hi Alex,


It’s great you were able to find what you were looking for. Please let us know any time you have any further queries.

Best regards,