Header Date Replacement Issue



We are currently using Java aspose-words-17.4.0.jar version jar file in our Java application to modify the word document .

I have attached a sample program in which we are trying to replace the date displayed (Japanese format:2017 年 7 月24 日) on top of every page’s header except first page.

When ever we are executing the attached Java Program**(TestHeaderFooterWords.java)** we can see the new date on every page’s header but size of the document is been reduced.

I have attached the original input word document(before date replacement:inputDateReplacement.docx) of size 149kb and also output word document(After date replacement:outputDateReplacmentDocument.docx) 106 kb.

Due to this we are seeing severe formatting issues when we later convert the word document to HTML.

Please analayze the issue and let us know the reasons for **RaisedToAspose.zip (235.7 KB)

Jinesh Parikh



Thanks for your inquiry. You are incorrectly updating the DOCPROPERTY field. Please use the following code to update this field.

Document doc = new Document(MyDir + "inputDateReplacement.docx");

OoxmlSaveOptions options = new OoxmlSaveOptions();
doc.save(MyDir + "output.docx", options);

Could you please share some more detail about your issue how file size causes formatting issue? We will then provide you more information about your query.



Thanks for your reply.

I have commented out old code in the sample program and added new code as suggested .The program executes fine but when we open (output.docx) the word document we received attached warning(DocumentWarning.png).

Even after document is opened we see below two issues.

1.Output document size is reduced from 149kb to 106kb as that is what happening in previous attached program as well.
2.Even if we opened the document after ignoring the warning we still can see the header is totally removed and date replaced is no where to seen in Header section.

I have attached sample word output document for your reference.

Please let me know If I missed anything inside the sample program and suggest a code change to resolve the above 2 issue.

Apart from this , please let me know the reason why the word document size is getting reduced after program execution since we are just replacing document property only.

Note : We are using Microsoft Office Version Microsoft Office Professional 2010 and Microsoft Word version 14.0.7184.5000.

Jinesh ParikhCodeChangeArtifcats.zip (243.3 KB)



Thanks for sharing the document.

You are using MS Word 2010. We suggest you please use following code example. We have tested the scenario using latest version of Aspose.Words for Java 17.9 and have not found the shared issue. Please use Aspose.Words for Java 17.9.

com.aspose.words.Document document = new com.aspose.words.Document(wordFile.getPath());



Please note that Aspose.Words mimics the same behavior as MS Word does. If you re-save your document using MS Word, file size will be reduced. You can use the output document with reduced file size where you want. There is no issue of using output document generated by Aspose.Words. If you face any formatting issue, please share complete detail of your use case. We will investigate the issue and provide you more information on this.