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

Free Support Forum - aspose.com

Incorrect language in the saved file (935)

Hi,


I have a document with some Thai text and I’m changing it to some English words. While iterating through the runs, I’m setting each run’s LocaleID to 1033 (en-US). When I save the file and open it in MS Word, language is still set to Thai.

Here’s the code I use:

String path = “Test.docx”;

InputStream inputStream = new FileInputStream(path);

Document document = new Document(inputStream);

inputStream.close();

String loremIpsumString = “Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus gravida ornare nibh, at pulvinar quam tristique vitae. Sed id urna sit amet mauris pretium blandit sed non elit. Pellentesque vestibulum venenatis nunc, condimentum hendrerit nunc tempus non. In id varius velit. Aenean a dui ut justo laoreet facilisis id id augue. Fusce ullamcorper vehicula ullamcorper. Pellentesque congue viverra ante id dapibus. Quisque scelerisque nulla vitae volutpat imperdiet. Nam est libero, ultrices eu erat at, tristique convallis nulla. In hac habitasse platea dictumst. Etiam pretium justo justo, pharetra rhoncus risus vestibulum sed. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Morbi consectetur varius dui, in volutpat arcu imperdiet eget. Praesent velit augue, tempus a diam et, vehicula consequat velit. Phasellus lobortis urna vel risus euismod, hendrerit dignissim quam pulvinar. Ut eu congue nisi.”;

String[] tokens = loremIpsumString.split(" ");
int tokensCount = tokens.length;
int counter = 0;
List runs = new ArrayList();

try {
document.accept(new DocumentVisitor() {
@Override
public int visitRun(Run run) throws Exception {
runs.add(run);

return super.visitRun(run);
}
});
} catch (Exception e) {
throw new RuntimeException(e);
}
for (Run run : runs) {
if (counter == tokensCount) {
counter = 0;
}
run.setText(tokens[counter++] + " ");
run.getFont().setLocaleId(1033);
}
document.save(“Test-aspose.docx”);

Can you check this?

Regards,
Zeljko
Hi Zeljko,

Thanks for your inquiry. Please use Font.ClearFormatting method to reset to default font formatting and set the font formatting according to your requirements. Hope this helps you.

String path = MyDir + "Test.docx";
InputStream inputStream = new FileInputStream(path);
Document document = new Document(inputStream);
inputStream.close();
String loremIpsumString = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus gravida ornare nibh, at pulvinar quam tristique vitae. Sed id urna sit amet mauris pretium blandit sed non elit. Pellentesque vestibulum venenatis nunc, condimentum hendrerit nunc tempus non. In id varius velit. Aenean a dui ut justo laoreet facilisis id id augue. Fusce ullamcorper vehicula ullamcorper. Pellentesque congue viverra ante id dapibus. Quisque scelerisque nulla vitae volutpat imperdiet. Nam est libero, ultrices eu erat at, tristique convallis nulla. In hac habitasse platea dictumst. Etiam pretium justo justo, pharetra rhoncus risus vestibulum sed. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Morbi consectetur varius dui, in volutpat arcu imperdiet eget. Praesent velit augue, tempus a diam et, vehicula consequat velit. Phasellus lobortis urna vel risus euismod, hendrerit dignissim quam pulvinar. Ut eu congue nisi.";
String[] tokens = loremIpsumString.split(" ");
int tokensCount = tokens.length;
int counter = 0;
java.util.List runs = new ArrayList();
try {
document.accept(new DocumentVisitor() {
@Override
public int visitRun(Run run) throws Exception {
runs.add(run);

return super.visitRun(run);
}
});
} catch (Exception e) {
throw new RuntimeException(e);
}

for (Run run : runs) {

if (counter == tokensCount) {
counter = 0;
}
run.getFont().clearFormatting();
run.setText(tokens[counter++] +
" ");
run.getFont().setLocaleId(
1033);
}

runs.get(0).getParentParagraph().getParagraphBreakFont().clearFormatting();
runs.get(0).getParentParagraph().getParagraphBreakFont().setLocaleId(1033);


document.save(
MyDir + "Test-aspose.docx");