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

Free Support Forum - aspose.com

After PageCount() not possible to call table.AppendChild(newRow)

There exists a problem with appending child rows to a table after calling the PageCount method of the document object.

Consider the following code:

We use a the first line in a table to clone it and append it to an existing table after setting its cell content.

var cloneRow = tableBookMark.BookmarkStart.ParentNode.ParentNode.ParentNode;
var table = cloneRow.ParentNode;
private void AddEmptyRowsToFillThePage(Document doc, CompositeNode cloneRow, CompositeNode table)
{
    for (int i = 0; i
    {
        Row newRow = cloneRow.Clone(true) as Row;
        SetCellContent(doc, newRow, 0, "HelloWorldText");
        table.AppendChild(newRow);
        int newPageCount = doc.PageCount; // <— calling doc.PageCount; won´t allow to append more rows
    }
}

Everything works as expected as long as the call to the page count method is commented out. As soon as we make a call to the

PageCount method no longer rows are appended to the table.

Hi Klaus,

Thanks for your inquiry. To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word document
  • Please create a standalone simple console application (source code without compilation errors) that helps us reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we’ll start investigation into your scenario and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip them and Click ‘Reply’ button that will bring you to the ‘reply page’ and there at the bottom you can include any attachments with that post by clicking the ‘Add/Update’ button.

Best regards,

1 Problems with Aspose Words

1.1 Page Count Problems

We were confronted with the task of adding rows to a table until all the rows of the table completely filled the page in order to avoid manipulations of the printed page.

The existing WORD API based solution adds rows to a table and retrieves the number of pages of the document. In case the page count increases after adding a row, this last row is removed.

We stumbled across several problems during out attempts to migrate the existing code base to Aspose Words. The most fundamental problem is how to get a correct page count of an existing document. The following code tries to retrieve the page count of an existing document:

using System;
using Aspose.Words;

namespace ShortestAsposeTest
{
    class Program
    {
        static void Main(string[] args)
        {
            Document document = new Document("PageCountTest.doc");
            // document.UpdatePageLayout();
            int pageCount = document.PageCount;
            Console.WriteLine(string.Format("{0} pages.", pageCount));
        }
    }
}

A visual inspection of the Word document PageCountTest.doc verified the existence of 3 pages. But the above code sample gets only 2 pages as a result. Calling the UpdatePageLayout method does not change the result.

Without a reliable way to get the number of pages of a document, even a document that has been loaded from disk without any further modifications, out formatting problems can’t be solved.

1.2 Problems removing rows

There seem to exist additional problems with Aspose. We have to remove the last row of the table, the row that was rendered on a new page. In case we remove this row with the following code:

table.RemoveChild(newRow);

a problem occurs. In case we save the corresponding document to disk as word, the row is removed. But in case we save the document content as a PDF document into a memory stream, the row is not removed.

As a workaround we have written a routine that save a document as a word document into a memory stream and reads it again from this memory stream before further processing.

Similar problems exist in case we want the remove the first row from a table, that acts as a template for the following rows.

Hi Klaus,

Thanks for your inquiry.

  1. While using the latest version of Aspose.Words i.e. 15.12.0, we managed to reproduce this issue on our end. We have logged this issue in our bug tracking system. The ID of this issue is WORDSNET-13040. Your thread has also been linked to this issue and you will be notified as soon as it is resolved. Sorry for the inconvenience. Also, your Word document uses ‘Source Code Pro’ font. Please zip and attach this font file for further testing.

  2. This is most likely because you have previously rendered the document or have called Document.UpdatePageLayout before removing row from the document. When either of these methods is called the document is laid out into pages and is stored into memory. If any content is inserted/removed after this action then it will be inserted into the Document Object Model but the layout of the pages will not be rebuilt to include this change until the page layout is updated again. So, I believe that calling Document.UpdatePageLayout method before saving to PDF will fix this issue on your end.

Best regards,