doc.Save and Page Count

Hi there,

I have written an application that generates a document containing fees that has ‘running totals’ at the top and bottom of each page. While I have managed to achieve this, it is very slow. I’ve found that the reason for this is that I have to save the document after adding each item, and the doc.Save function is quite slow (especially for large documents). I have two questions:

  1. I haven’t used the Aspose command doc.PageCount as I found it to be unreliable, but should this function work without saving the document first?
  2. Is there any way that the doc.Save command could be any quicker? Or is it just best to use it sparingly?

To any other members of this forum - has anyone tried to do something similar and if so did they have similar difficulties?

Many thanks,
Alice

Hi Alice,

Thanks for your inquiry.

  1. Yes, you can get the number of pages in the document as calculated by the most recent page layout operation by using Document.PageCount property and without saving the document.

  2. Have you tried the latest version of Aspose.Words 14.9.0? If yes, are you getting this problem during saving Word document to PDF/XPS/Images formats only? In this case, on average, Aspose.Words layouts 10 pages per second; so, the extra amount of time Aspose.Words takes to format a document into pages depends on the number of pages your Word document has. However, could you please attach your input Word document you’re getting this problem with here for testing? We will investigate the issue on our end and provide you more information.

Best regards,

Hi Awais, thanks for the reply.
I can try some more testing with the doc.PageCount property. I was just getting some incorrect outputs, for example I had a document with 5 pages and doc.PageCount was telling me I had 10 pages. As a workaround I’ve been using Interop to find the page count, but this involves saving the document constantly.
I’m currently using Aspose.Words 13.11.0, but we are considering getting Aspose.Total in the near future so if this helps the speed that would be fantastic!
I’m just saving the document to .doc format. See the attached example document. I’m saving the document after adding entry in the table, and it’s taking between 2 and 3 seconds per item. It’s probable that we will use this application for documents with over 100 pages.
Many thanks,
Alice

Hi Alice,

Thanks for your inquiry. When using Aspose.Words for .NET 14.9.0, the Document.PageCount property returned correct number of pages i.e. 6 and opening and saving this document to DOC format was completed instantly on my end. So, I suggest you please upgrade to the latest version. I hope, this helps.
https://releases.aspose.com/words/net

However, in case the problem still remains, please create a standalone simple console application (source code) that helps us reproduce your problem on our end and attach it here for testing. As soon as you get this simple application ready, we’ll start further investigation into your issue and provide you more information.

Best regards,

Hi Awais,
That’s great. I’ll have another go using doc.PageCount once we’ve upgraded. If I’m still having issues I’ll do as you’ve suggested and create a simple app and attach it here.

Many thanks,
Alice

Hi Alice,

Thanks for your inquiry. Please let us know if you have any troubles and we will be glad to look into this further for you.

Best regards,

Hi Awais,

I’m afraid our upgrade to the newest version of Aspose Total has not solved my issue. See attached for a small example web app.

As you can see, I am trying to output the page number of each item in the table, but the page number always remains 1, even though there are 9 pages.

Many thanks,
Alice

Hi Alice,

Thanks for your inquiry. Please use the following article and code to fix this issue:
https://reference.aspose.com/words/net/aspose.words/document/updatepagelayout/

for (int i = 0; i < 100; i++)
{
    builder.InsertCell();
    builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(50);
    builder.Write(i.ToString());
    builder.Writeln("\n\n");
    builder.InsertCell();
    builder.CellFormat.PreferredWidth = PreferredWidth.FromPercent(50);
    doc.UpdatePageLayout();
    pageCount = doc.PageCount;
    builder.Write(pageCount.ToString());
    builder.EndRow();
}

I hope, this helps.

Best regards,