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

Free Support Forum - aspose.com

Document stats are not being updated properly

Have Microsoft Word document docx with a proper hyperlink
HYPERLINK “mailto:firstname.lastname@organization.orgfirstname.lastname@organization.org
Open it with MS Word and in the menu File->Info see Words 52.
Now open document
Document document = new Document(“path”);
and run
document.getBuiltInDocumentProperties().get(“Characters”).getValue() -> 335
document.getBuiltInDocumentProperties().get(“Words”).getValue() -> 58
document.getBuiltInDocumentProperties().getBytes() -> 992720
document.getRange().getText().getBytes().length -> 391

do replace in the document of
firstname.lastname@organization.org with anonymous@great.com more words even more short words

The replacement happened. And the document was saved.

HYPERLINK “mailto:anonymous@great.com more words even more short words” anonymous@great.com more words even more short words

therefor, I expect all numbers to be changed accordingly

document.getBuiltInDocumentProperties().get(“Characters”).getValue() -> 335
document.getBuiltInDocumentProperties().get(“Words”).getValue() -> 58
document.getBuiltInDocumentProperties().getBytes() -> 992720
document.getRange().getText().getBytes().length -> 425

Open document in MS Word, menu File -> Info see Words 58.

Open the document with API and call stats again
document.getBuiltInDocumentProperties().get(“Characters”).getValue() -> 335
document.getBuiltInDocumentProperties().get(“Words”).getValue() -> 58
document.getBuiltInDocumentProperties().getBytes() -> 988506
document.getRange().getText().getBytes().length -> 425

@lion.brotzky

Could you please ZIP and attach your input Word document here for testing? We will investigate the issue and provide you more information on it.

Sample - Copy.docx (969.6 KB)
I noticed this issue 6 months ago, this is why started to use getText().length()

@lion.brotzky

Please call Document.updateWordCount method as shown below to get the desired output. We have tested the scenario and have not found the shared issue. The MS Word and Aspose.Words return same numbers of characters and words. Please check the attached screenshot of MS Word 2019.
Builtin Properties.jpg (115.0 KB)

Document document = new Document(MyDir + "Sample - Copy.docx");
document.updateWordCount(true);

System.out.println(document.getBuiltInDocumentProperties().getCharacters()); //324
System.out.println(document.getBuiltInDocumentProperties().getWords()); //56
System.out.println(document.getBuiltInDocumentProperties().getBytes());
System.out.println(document.getRange().getText().getBytes().length);