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.