NUmber of Pages in Word document

Hi,
I’m using Document.BuiltInDocumentProperties.Pages to get the number of pages in a word document.
However it is not giving actual page count for some of the documents. The attached document has two pages, but the BuiltInDocumentProperties return 1.
Is it reliable to use PageNavigator class instead? Is it still in Beta?

Hi

Thanks for your inquiry. If you need to get page count you should use Document.PageCount property. Please see the following link for more information:
https://reference.aspose.com/words/net/aspose.words/document/pagecount/
Note, this feature is available starting from Aspose.Words 6.0.0.
Best regards.

Thanks Alexy,
I tried using the Document.PageCount property to get the number of pages in my document. It works for some document (90% files), but the count differs for some files. Attaching one such file with discrepancy in count. Even though this is a 3-page document, the Pagecount property returns 2. (Surprisingly, BuiltInProperties.Pages returns 3 for this document, but PageCount property is found to be far more reliable than BuiltInProperties.Pages)
regards
Prasanth

Hi

Thank you for additional information. I managed to reproduce the problem on my side and created new issue #8693 in our defect database. I will notify you as soon as it is resolved.
Best regards.

Please let me know as well. I have encountered this problem and am anxious for a resolution!

Hi

Thanks for your inquiry. The notification will be posted in this forum thread. However, please attach your document here for testing. The problems might have different reasons, so I need to check your document.
Best regards.

Thank you. The erroneous pagecounts are for documents that existed in memory only (before being appended to a larger document I get the page count in order to manually build a table of contents in a format that unfortunately doesn’t lend itself to Word’s TOC functions). However, I decided I had better take a look at them, and, you are correct. I was able to identify and remedy two different conditions that resulted in what I thought were erroneous counts:

  1. Had to do with where I inserted the pagebreaks–adding the pagebreak to the end of the “master” document resulted in an extra line at the beginning of the appended document. Adding the pagebreak to the beginning of the appended document resolved the issue.
  2. the other was caused by a missing line break before a horizonal line–Aspose’s renderer broke the line differently than Word.

However, there are STILL some unaccounted for pagecounts that are off. e.g. document.pagecount for the attached file, prior to saving and immediately following an updatePageLayout, returns 8 pages instead of 7. Your help is greatly appreciated.
-Mark

Hi Mark,

Thanks for your request. The problem occurs because there are merged cells in your table which duplicates the content. This can occur when you convert HTML to DOC and there is a table with rowspan or colspan, Aspose.Words represents them as merged cells, but each of merged cell contains the same content, this causes the problems during rendering or converting to PDF. I linked your request to the appropriate issue. You will be notified as soon as it is resolved.
As a temporary workaround, you can try using the following code:

// Open HTML document
Document doc = new Document("AB96.DOC");
// Get collection of cells in the docuemnt
NodeCollection cells = doc.GetChildNodes(NodeType.Cell, true);
// Loop through all cells and search for merged cells
foreach(Cell cell in cells)
{
    if (cell.CellFormat.HorizontalMerge == CellMerge.Previous ||
        cell.CellFormat.VerticalMerge == CellMerge.Previous)
    {
        // Remove content from merged cells
        cell.RemoveAllChildren();
    }
}
// Save as image
doc.SaveToImage(0, doc.PageCount, @"Test199\preview.tif", null);

Hope this helps.
Best regards.

That worked! Thank you for the quick reply!

The issues you have found earlier (filed as 7739) have been fixed in this update.

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

The issues you have found earlier (filed as WORDSNET-2295) have been fixed in this Aspose.Words for .NET 20.6 update and this Aspose.Words for Java 20.6 update.