Getting font size wrongly

Hi,

I have created a document in MSWord in docx format.I am using aspose word for java 10.0.

I am taking the default fontfamily using the code,

String defaultFontName = doc.getDocument().getFontInfos().get(StyleIdentifier.NORMAL).getName();

gives Calibri, the correct one.

and taking the each run font-family using the code,

Run run = (Run) this.node;
Font f = run.getFont();
System.out.println("Font-family = " + font.getName());

gives Times New Roman, but the text font family is calibri in document.

Why the default font and run font name differs as i didn’t change the font in document?
How to take each run font as calibri because its a right one?

Hi
Thanks for your request. This occurs because in your document font is defined in Theme. Unfortunately, Aspose.Words does not provide an ability to access Theme’s information. However, Themes are fully preserved upon processing.
As a workaround, you can convert your document to DOC and then get font of runs. You will get the correct font in this case because DOC format does not support Themes, and formatting defined in Themes is expanded into direct Run formatting.

Document doc = new Document("C:\\Temp\\in2.docx");
// Convert DOCX to DOC to fix the problem.
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
doc.save(byteStream, SaveFormat.DOC);
InputStream inputStream = new ByteArrayInputStream(byteStream.toByteArray());
// Create com.aspose.words.Document from InputStream.
doc = new Document(inputStream);
// Here you can get font of each run.
// .......................

Hope this helps.
Best regards,

Hi,

Thanks for your reply.

The issues you have found earlier (filed as WORDSNET-3312) have been fixed in this .NET update and this Java update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(1)