Some Fields are not updated via updateFields

Hi,

With the latest Aspose version (17.7.1) . Some of the Fields like NUMWORDS, NUMCHARS are not updated,

For the attached code sample, we can see that number of pages is shown correctly whereas number of words and number of characters is shown as 0.

Can you please analyse the code and let me know what exactly can be done to achieve the correct output.

ThanksUpdateFieldsSampleCode.zip (2.0 KB)

@tejashreegupta,

Thanks for your inquiry. Please call Document.updateWordCount and Document.updateFields method before saving the document to get the desired output. Document.updateWordCount method updates word count properties of the document.

doc.updateWordCount(true);
doc.updateFields();

doc.save(MyDir + "output.doc");
doc.save(MyDir + "output.docx");
doc.save(MyDir + "output.pdf");

Hi Tahir,

Thanks for the quick solution. I can confirm that the desired result is achieved once I call updateWordCount() on the document object.

Thanks

@tejashreegupta,

Thanks for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.

Hi @tahir.manzoor,

Although

doc.updateWordCount(true);

Solves the issue with updation of word and character count. I could see that it heavily impacts the performance of document generation especially time consumption.
Hence this solution is not acceptable.

Can you please suggest any less expensive way to update the word and character counts ?

Thanks
Tejashree

@tejashreegupta,

Thanks for your inquiry. Please note that performance and memory usage all depend on complexity and size of the documents you are generating.

Please ZIP and attach your input Word document here for testing. We will investigate the issue on our side and provide you more information.

Hi @tahir.manzoor,

For a 1054 page document the generation time was about 184 sec.
Whereas if I do not call updateWordCount() the generation time for same document was about 24 sec

Also,

I am unable to attach the document due to upload limit restriction on the size of my zipped document.
Can you please provide me any email to which I can forward the same ?

Thanks

@tejashreegupta,
@tahir.manzoor should be able to generate similar document himself with that code we’ve shared earlier by increasing the number of paragraphs and tables parameter.

The updateWordCount is very expensive with 8x performance impact, which won’t be acceptable with our customers.

@kumaraswamy.m,

Thanks for your inquiry.

We have tested the scenario using latest version of Aspose.Words for Java 17.8 with following code example. This code example generates document with 1251 pages and takes around 48 seconds. We suggest you please use latest version of Aspose.Words for Java 17.8.

long startTime = System.currentTimeMillis();

Document doc = new Document();
DocumentBuilder docBuilder = new DocumentBuilder(doc);

for(int i = 0; i < 5000; i++) {
    docBuilder.insertHtml("Watermarks are text or pictures that appear behind document text. They often add interest or identify the document status, such as marking a document as a Draft.You can add text watermarks, such as Draft or Confidential, to your document. You can create your own custom watermark such as a company logo.");
    docBuilder.insertHtml("When the watermark picture property is set the user is prompted to choose if the image is to be embedded. If the user chooses yes than the image is embedded in the template and the internal image is used. The WordCOMDriver has been updated to use watermarks from both the template as well as from external locations. the watermark is specific to the current section while in the original implementation it was document wide. This means you can have a different watermark per master page the text and picture properties have been merged into a single feature, watermak RPE will create an image watermark if watermark image is not empty. If watermark image is empty it will use the text if not empty added an advanced property window for these properties");
}

docBuilder.insertField("NUMWORDS");
docBuilder.insertField("NUMCHARS");
docBuilder.insertField("NUMPAGES");
doc.updateFields();
docBuilder.insertHtml("<br /><br /><br />");
for (Field field : doc.getRange().getFields())
{
    docBuilder.insertHtml("<br />");
    docBuilder.insertHtml(field.getFieldCode()+" : "+field.getResult());
}

doc.updateWordCount(true);

long endTime = System.currentTimeMillis();
System.out.println("Total execution time: " + (endTime - startTime) + "ms");

Hi @tahir.manzoor ,

The document that took 184 sec is much more complicated than just simple paragraphs, It has tables and images inside it.
Could you provide me with an alternative to share the document with you (cannot attach it here due to size limitation). so that you could investigate the performance issue at your end.

Thanks
Tejashree

@tejashreegupta,

Please ZIP and upload sample document on Dropbox or any other file hosting service and share the download link here for us to test this scenario. We will investigate the issue on our side and provide you more information.

@tejashreegupta, Why do we need to upload the document? We should share a standalone java code that could generate such a document along with doc.updateWordCount(true).

@tahir.manzoor I hope that works.

@kumaraswamy.m,

Yes, you may share Java code example that you are using at your end to reproduce this issue. Thanks for your cooperation.

Hi @tahir.manzoor,

Please find attached code to replicate the issue.

Thanks
Tejashree

TestAsposePerformance.zip (764.7 KB)

@tejashreegupta,

Thanks for sharing the code. Please note that CPU performance and memory usage all depend on complexity and size of the documents you are loading/generating. We have tested the scenario using latest version of Aspose.Words for Java 17.8 and it takes around 49 seconds at our end. Please check the attached image for test results. output.png (24.1 KB)

@tahir.manzoor,
Is this execution time for a 2000 paragraph document as hardcoded in the code provided by me ?
Also, can you please try generating the same document without updateWordCount() and record the % difference between the average document generation time.

Regards
Tejashree

@tejashreegupta,

Thanks for your inquiry. We have tested the scenario on following environment. The execution time is around 130 seconds when Document.updateWordCount is not called. Could you please share some detail about your working environment? We will then setup the same environment at our end and test this scenario. Thanks for your cooperation.

OS architecture: amd64
Java VM name: Java HotSpot™ 64-Bit Server VM
Java version: 1.8.0_20

@tahir.manzoor,
From your previous comments you mentioned that the docgen took 49 Seconds with the latest version (comment#14) and you mentioned that it takes 130 seconds when updateWordCount is not called.
But it is the other way at our end. The docgen time is more when updatewordcount is called.
Can you please verify this at your end ?

Also,
I am testing this on
OS architecture: amd64 & using ibm JRE 7

Thanks

@tejashreegupta,

Thanks for sharing the detail. We have tested the scenario using latest version of Aspose.Words for Java 17.9 with IBM Java 1.7 and have not found the performance issue with Document.updateWordCount method. Please check the attached results. We commented the following code in writeDocument method to test this scenario because there is no need of this code to check performance of Document.updateWordCount.

doc.updateFields();

for (Field field : doc.getRange().getFields())
{
    builder.insertHtml("<br />");
    builder.insertHtml(field.getFieldCode()+" : "+field.getResult());
} 

save(doc, baseFolder);