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

Free Support Forum - aspose.com

Wrong PageCount value

I am using trial version of Aspose.Words (from Total pack). When I am trying to create a Document object from stream - I receive a document object that have a PageCount value less than source file have. To check that my source file fine, i am writes a stream to file and receive a valid file with valid number of pages. Any suggestion?

Hello

Thanks for your request. Could you attach the document you are getting issues with? I will check the problem on my side and provide you more information.
Best regards,

public List<byte[]> Convert(byte[] sourceContent, ValidFormat outputFormat)
{
    List<byte[]> result = new List<byte[]>();
    MemoryStream sourceStream = new MemoryStream(sourceContent);
    MemoryStream resultStream = null;

    try
    {
        Document doc = new Document(sourceStream);
        ImageSaveOptions saveOptions = new ImageSaveOptions((SaveFormat)outputFormat);
        saveOptions.PageCount = doc.PageCount;

        for (int i = 0; i < doc.PageCount; i++)
        {
            saveOptions.PageIndex = i;

            resultStream = new MemoryStream();
            doc.Save(resultStream, saveOptions);
            result.Add(resultStream.ToArray());
        }
    }
    catch (Exception exc)
    {

    }
    finally
    {
        sourceStream.Dispose();
        if (resultStream != null)
            resultStream.Dispose();
    }

    return result;
}

After
Document doc = new Document(sourceStream);
doc.PageCount = 12

Hello

Thank you for additional information. I cannot reproduce the problem on my side using the latest version of Aspose.Words (9.4.0). I use the following code for testing:

//Read doc form file.
byte[] docBytes = File.ReadAllBytes("WindowsXP.doc");
//Create MemoryStream from byte array
MemoryStream docStream = new MemoryStream(docBytes);
Document doc = new Document(docStream);
Console.WriteLine(doc.PageCount);

Also you can try calling UpdatePageLayout method to rebuild the page layout of the document:
https://reference.aspose.com/words/net/aspose.words/document/updatepagelayout/
You can download the latest version from here:
https://releases.aspose.com/words/net
Best regards,

Hi. Just checked your code on my machine - 12 pages instead of 226!
I have Aspose.Words 9.4.0.0 file version, MS Office 2007. May be the problem in Windows 7 that I am working on it?

P.S. I have tried UpdatePageLayout method - same result…

Hi,

Thanks for your inquiry. Most likely, you use Aspose.Words in evaluation mode and document is truncated. There is evaluation limitation of maximum number of paragraphs in the document. You should see the following text in the output documents.
This document was truncated here because it was created using Aspose.Words in Evaluation Mode.
That is why doc.PageCount; returns incorrect value (less than expected).
If you want to test Aspose.Words for without the evaluation version limitations, you can request a 30-day Temporary License. Please refer to
https://purchase.aspose.com/temporary-license
Best regards.

Thanks, Alexey.
Now it’s ok.