Locale system (jvm) dependant converting vignettes from docx to pdf

Hello,
We have a problem when aspose saves from docx to pdf having locale dependant vignettes like the ones shown below.
Aspose trusts the jvm locale to save in pdf format. Our product has multilanguage support so we need a solution, we cannot change the system locale on each word document saved in pdf because of many obvious reasons, one of them, concurrence.
I’ve been searching for a solution on the forum, the only one i’ve found is Preserve Spanish Language List labels in Word DOCX Document after Converting Saving As to PDF using VB .NET - Vignettes Language - WORDSNET-7506, which does not solve my problem. Any tip? thanks in advance.


Primero.- El período impositivo del IVTM coincide con
el año natural, y se devenga el primer día de dicho período, conforme al art.
96.1 y 2 del R.D.L. 2/2004, de 5 de marzo, por el que se aprueba el Texto
Refundido de la Ley reguladora de las Haciendas Locales (en adelante, RDL
02/04).

Segundo.- 2.1. Según el art. 95. 6 c) del R.D.L.
02/04, las ordenanzas fiscales podrán establecer una bonificación de hasta el
100 por 100 para los vehículos históricos o aquellos que tengan una antigüedad
mínima de veinticinco años, contados a partir de la fecha de su fabricación o,
si ésta no se conociera, tomando como tal la de su primera matriculación o, en
su defecto, la fecha en que el correspondiente tipo o variante se dejó de
fabricar. En la Ordenanza Fiscal Municipal nº 21, reguladora del IVTM (en
adelante OFM 21), en su artículo 5.1 se recoge un porcentaje de bonificación
para estos vehículos del 100%.

@tsyses,

Thanks for your inquiry. In fact there is no setting in MS Word document that controls the language of the document as a whole. Instead, language is set for each Run separately. Font.LocaleId property controls this setting.

In your case, we suggest you please iterate through all runs in the document and choose LocaleId that is occurring most often and set the set the locale accordingly.

First of all, thanks for your attention, your response was faster than I expected.

I’ve tested your solution like this but could not get the output that I expected, anything wrong?

ByteArrayInputStream bAIS = new ByteArrayInputStream(myData);
Document doc = new Document(bAIS);
Map<String, Integer> localeStr_LocaleId = new HashMap<String, Integer>();
localeStr_LocaleId.put(“es_ES”, Integer.parseInt(“456”, 16));
localeStr_LocaleId.put(“ca_ES”, Integer.parseInt(“c0A”, 16));
localeStr_LocaleId.put(“eu_ES”, Integer.parseInt(“403”, 16));
localeStr_LocaleId.put(“gl_ES”, Integer.parseInt(“42D”, 16));
Node node = doc;

    while(node !=doc.getLastSection().getBody().getLastParagraph().getLastChild()) {
        if (node != null) { 
            if (node.getNodeType() == NodeType.RUN) {
                try {
                    (((Run) node).getFont()).setLocaleId(localeStr_LocaleId.get("es_ES"));
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
        node = node.nextPreOrder(doc);
    }
    documentAspose.save(bAOS,SaveFormat.PDF);

@tsyses,

Thanks for your inquiry. You are setting the LocaleId of Run node that is incorrect. You need to get the LocaleId of Run node. E.g. If LocaleId of Run node is 1025. Microsoft Word recognizes the text of this Run node as Arabic - Saudi Arabia. In this case, you need to set the Locale for JVM as Arabic. Please check the following line of code.

Locale.setDefault(new Locale("ar", "SA"));

Thanks for the answer, as I posted in the first inquiry, I cannot change the JVM default locale, we have en_US, which is the default locale. This cannot be changed for many reasons, one of them as I told on first inquiry, the concurrence.
We have multilanguage products so we cannot change the default idiom for all the users. Is there any way to set a locale in order save a Word document into PDF? If not, will it be fixed anytime soon?
Saving to PDF should respect the languageId of each Word node, otherwise, if we have a multilanguage document like an user manual, all the lists would show with same idiom.

@tsyses,

Thanks for your inquiry. Please note that Aspose.Words mimics the same behavior as MS Word does. If you convert your Spanish document under English locale, you will get the same output. In this case, the field’s result, list labels etc. will not be correct. In your case, we suggest you please set the value of FieldOptions.FieldUpdateCultureSource property as FieldUpdateCultureSource.FieldCode.

Could you please ZIP and attach your input Word document that you want to convert under English locale? Please also share the expected output PDF. We will then provide you more information about your query.

Hello, I’ve tested using the culture source you told me “documentAspose.getFieldOptions().setFieldUpdateCultureSource( FieldUpdateCultureSource.FIELD_CODE );” but I got the same output, english when i expected spansih.

When I save - publish a word to pdf having the lang tag of styles.xml like <w:lang w:val=“es-ES” it is saved as it should in pdf, in spanish. Same happens when i change <w:lang w:val=“en-US”, I can save it into pdf file and it shows english labels. Otherwise, with aspose, I allways get the same output, english, because our JVM locale setting is “en_US”.

I attach 2 documents test_vignettes.zip (173.7 KB) and their pdf output so you can test, one in english, one in spanish, with the same JVM we should be capable of saving into pdf with the language they have on their settings.

@tsyses,

Thanks for your inquiry.

You do not need to use this line of code for list labels.

We have converted the shared documents to PDF under English culture and have not found any issue with output documents. Please check the attached output PDF file. US-18.4.pdf (14.1 KB)
ES-18.4.pdf (13.9 KB)

In case you are using older version of Aspose.Words, we suggest you please upgrade to the latest version of Aspose.Words for Java 18.4.

Thanks, I’ve tested with the last version and this issue is solved, we have some customers with jre 1.5, so we are stuck on that version until they all have 1.6 , anyways this will help us with the ones that demand that this issue have to be solved. Sorry for bothering you, I should’ve tested last version before opening this thread.

@tsyses,

It is nice to hear from you that your problem has been solved. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.