Hi
The attached word document contains four lines, on each line the name of the language and a field for the date / time. Via “Language Ribbon / Language / Set Proofing language” the language for each line was set accordingly.
When updating the fields (F9) in Word, the date will be rendered in the language specified (see screenshot).
Code
final boolean updateFields = true;
final String folder = “c:/temp/”;
try (
FileInputStream fis = new FileInputStream(folder + “fields.docx”);
FileOutputStream fosDocx = new FileOutputStream(folder + “fields.out.docx”);
FileOutputStream fosPdf = new FileOutputStream(folder + “fields.out.pdf”);
FileOutputStream fosHtml = new FileOutputStream(folder + “fields.out.html”)) {
Document wordDoc = new Document(fis);
wordDoc.getFieldOptions().setFieldUpdateCultureSource(FieldUpdateCultureSource.FIELD_CODE);
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
pdfSaveOptions.setUpdateFields(updateFields);
wordDoc.save(fosPdf, pdfSaveOptions);
HtmlSaveOptions htmlSaveOptions = new HtmlSaveOptions(SaveFormat.HTML);
htmlSaveOptions.setUpdateFields(updateFields);
wordDoc.save(fosHtml, htmlSaveOptions);
OoxmlSaveOptions ooxmlSaveOptions = new OoxmlSaveOptions(SaveFormat.DOCX);
ooxmlSaveOptions.setUpdateFields(updateFields);
if (updateFields) {
wordDoc.updateFields();
}
wordDoc.save(fosDocx, ooxmlSaveOptions);
}
Issue 1
When running the above code, the output of the dates will always be according to the locale returned by Locale.getDefault(). Word takes into consideration the languages, thus resulting in the appropriate date formatting for each language (tested with Word field update via F9 and storing to PDF / HTML formats).
Issue 2
HtmlSaveOptions#setUpdateFields(false) and OoxmlSaveOptions#setUpdateFields(false) seems to be ignored; the created html and word document always have the fields updated.
When calling the above code with updateField = false, the PDF Output shows the initial, non-updated field values. I’ve checked the Word output by inspecting document.xml, because Word will always update the fields when the document is opened.
Issue 3
I’ve already had a look at <a href="https://forum.aspose.com/t/47512. When having only one locale per document, setting the corresponding locale via Locale.setDefault would be an option in a single-threaded environment. As sherter stated in the mentioned forum thread, this will not work in a multi-threaded environment due to race condition (at least not without appropriate locking, which would reduce performance). Thus a way to set the locale on a per-document base would be highly appreciated, e.g. for example via com.aspose.words.Document#setLocale(Locale) or a similar method, which would then be used for standalone field update or in conjunction with conversion to e.g. PDF, HTML or Plain Text. This would solve issue 1 at least for documents with only a single locale (which is probably the most likely case anyway).
Tested with Aspose Words 16.2, 16.4 and 16.5.
Kind regards
Stephan
bsiagch:
Issue 1When running the above code, the output of the dates will always be according to the locale returned by Locale.getDefault(). Word takes into consideration the languages, thus resulting in the appropriate date formatting for each language (tested with Word field update via F9 and storing to PDF / HTML formats).
bsiagch:
Issue 2HtmlSaveOptions#setUpdateFields(false) and OoxmlSaveOptions#setUpdateFields(false) seems to be ignored....
bsiagch:
Issue 3Thus a way to set the locale on a per-document base would be highly appreciated, e.g. for example via com.aspose.words.Document#setLocale(Locale)....
Hi Tahir
Issue 1
Great, thank you.
Issue 2
When SaveOptions.UpdateFields is false, the fields are not updated when saving to PDF Format (which is correct). But the fields are updated when saving the HTML (may be correct, see ) or DOCX (incorrect).
When running the above code with updateFields = false, the PDF output is correct and shows the date according to the word document (i.e. Friday, 1. July 2016 16:06:24) but the HTML Output and the DOCX Output show the current date and time.
You mentioned that this option is only relevant when exporting to a fixed page format (thus PDF and DOCX). This would mean that when exporting to HTML this will be ignored and fields are always updated in this case (because HTML is not a fixed page format). Is that correct?
Issue 3
I didn’t know CurrentThreadSettings, that’s exactly what I need, thanks.
Kind regards
Stephan
Hi Tahir
Thanks for the clarification.
Kind regards
Stephan
The issues you have found earlier (filed as WORDSJAVA-1394) have been fixed in this .NET update and this Java update.
This message was posted using Notification2Forum from Downloads module by aspose.notifier.
Tested successfully with 16.8.0, thank you.