Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Thu Jun 17, 2021 9:24 pm

Hi,
I'm trying to getting number of char with spaces on word document from an azure function. With some documents, the number of characters returned is negative
This is my code :

Code: Select all
int nbPages = 0;
                        int nbChars = 0;
                        int nbCharsWithSpaces = 0;
                       
                        using (var memory = new MemoryStream())
                        {                           
                            try
                            {                               
                                byte[] buffer = new byte[1024 * 64];
                                int nread = 0;
                                while ((nread = fileInfo.Stream.Read(buffer, 0, buffer.Length)) > 0)
                                {
                                   memory.Write(buffer, 0, nread);
                                }
                                memory.Seek(0, SeekOrigin.Begin);

                                spireDoc.LoadFromStream( memory,FileFormat.Docx);
                                nbPages = spireDoc.GetPageCount();
                                nbCharsWithSpaces = spireDoc.BuiltinDocumentProperties.CharCountWithSpace;
                                nbChars = spireDoc.BuiltinDocumentProperties.CharCount;
                                log.Info("Nb pages with SPire.Doc=[" + nbPages + "]");
                                log.Info("Nb charac =[" + nbChars + "]");
                                log.Info("Nb charac with spaces=[" + nbCharsWithSpaces + "]");


And the result :
2021-06-17T21:09:04.786 [Info] Nb pages with SPire.Doc=[8]
2021-06-17T21:09:04.786 [Info] Nb charac =[-2147483648]
2021-06-17T21:09:04.786 [Info] Nb charac with spaces=[-2147483648]

PS : i use 7.8.8 Spire.Doc version

Any idea ?

Thanks

ocollettoto
 
Posts: 2
Joined: Thu Jun 17, 2021 1:08 pm

Fri Jun 18, 2021 7:51 am

Hello,

Thanks for your inquiry.
Since you are using a very old version of Spire.Doc, we recommend you upgrade to the latest version (the latest version is Spire.Doc Version:9.6.10) and try it again. If the issue still occurs, to help us investigate further, please provide your input file. You could send it to us (support@e-iceblue.com) via email. Thanks in advance for your assistance.

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Fri Jun 18, 2021 1:56 pm

The issue is still here with version 9.6.10. In send you a email with file attchement.
Regards

ocollettoto
 
Posts: 2
Joined: Thu Jun 17, 2021 1:08 pm

Mon Jun 21, 2021 6:10 am

Hello,

Thanks for providing your input file via email.
I tested your case and did reproduce your issue. I have logged it in our bug tracking system with the ticket SPIREDOC-6178. If there is any update, we will let you know. Apologize for the inconvenience caused.
If you have any other questions related to our products, please feel free to contact us.

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Mon Jun 21, 2021 9:25 am

Hello,

This is to tell you about the update of the issue SPIREDOC-6178.
When our Spire.Doc processes Word documents, it actually reads the actual data inside the Word document directly. After parsing your Word document, we found that there is actually no CharCountWithSpace and CharCount related properties inside it, so it returns the value: int.MinValue (-2147483648).
To solve this issue, please use the code "spireDoc.UpdateWordCount();" to update the number of characters in the document before getting the BuiltinDocumentProperties.

If you have any other questions, just feel free to contact us.

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Return to Spire.Doc