One Table Split across multiple pages - need to draw bottom border on the last row on each page

Hello,

I have created a table using document builder. It splits fine on page break, prints header on each page etc. I want to draw a bottom border on the last row of each page. How can I achieve this?

Thank You,
AM

Hello

Thank you for your interest in Aspose.Words. MS Word document is flow document and does not contain any information about its layout into lines and pages. Our Rendering Engine layouts documents into lines and pages.
But unfortunately, there is no public API, which allows you to determine where page starts or ends. Your request has been linked to the appropriate issue. You will be notified as soon as this feature is supported.
Best regards,

Thank You. Can you do this after re-opening the document?

Hi there,
Thanks for your inquiry.
No, I’m afraid even after reloading a document there is no built in method to find the page number of a node.
However, you may be able to use the code found on this thread from a customer with a similar request.
I have written a quick implementation which should achieve what you are looking for, it uses the code from the thread above which I have included as an attachment to this post. It may need some tweaking to get it to work in all cases for your document.

// Load the document
Document doc = new Document("Document.docx");
// Retrieve the table to work with from the document. It is assumed this is the first table in the document.
Table table = (Table) doc.GetChild(NodeType.Table, 0, true);
// Get all the paragraphs from this table.
Node[] paragraphs = table.GetChildNodes(NodeType.Paragraph, true).ToArray();
// Wrap nodes into a new ArrayList
ArrayList paragraphsArray = new ArrayList(paragraphs);
// Find page numbers of each node, the ordering of each page number will match the order of the paragraphs in the array.
ArrayList pageList = GetPageNumberOfNodes(paragraphsArray);
// Previous page of the last node processed, by default this will start at page one.
int prevPage = 1;
for (int i = 0; i <pageList.Count; i++)
{
    // Current page number
    int page = (int) pageList[i];
    // If this number is different the row is on the next page.
    if (page != prevPage)
    {
        // Find the row from the paragraph, use the row before as that will be the last row on the previous page.
        Row row = (Row) paragraphs[i].GetAncestor(NodeType.Row).PreviousSibling;
        foreach(Cell cell in row.Cells)
        {
            // Change border color of this row.
            cell.CellFormat.Borders.Bottom.Color = Color.Red;
        }
        // Set this as the page most recently processed.
        prevPage = page;
    }
}

If you have any further queries, please feel free to ask.
Thanks,

Thank you once again. I am going to try suggested workaround. Hopefully it works.

Somehow the suggested code was drawing border on wrong rows, the pattern I observed was

when page < pageCount then desired row-current page -1
page = PageCount then desiredrow - currentpage -2

I did not have to worry about lastpage/last row since rw.isLastRow took care of it.

If (page <> prevPage AndAlso page < doc.PageCount) Then
    rw = CType(paragraphs(i).GetAncestor(NodeType.Row).PreviousSibling, Tables.Row)

    For j As Integer = 0 To page - 1
        If Not rw.NextSibling Is Nothing Then
            rw = rw.NextSibling
        End If
    Next

    For Each cl As Tables.Cell In rw.Cells
        cl.CellFormat.Borders.Bottom.LineStyle = LineStyle.Hairline
        cl.CellFormat.Borders.Bottom.LineWidth = 0.5
    Next
    prevPage = page
End If

Hi there,
The code work as expected on my side for a simple template, but the layout of your template may differ and the results may differ.
If you have any troubles please feel free to post your template here and I will take a look at it for you.
Thanks,

The issues you have found earlier (filed as WORDSNET-2978) have been fixed in this .NET update and this Java update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(71)