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

Free Support Forum - aspose.com

DOCX font name issue

Hi,

I get wrong font name. I used following code:

public class TestFont {
public static void main(String args[]) throws Exception {
Document doc = new Document(“d:/test/TestFont.docx”);

List runs = getDocumentRuns(doc);

System.out.println(runs.get(1).getFont().getName()); // prints Times New Roman, but should be Calibri.
}

private static List getDocumentRuns(com.aspose.words.Document document)
throws Exception {
final List runList = new ArrayList();

document.accept(new DocumentVisitor() {

@Override
public int visitRun(Run run) throws Exception {
runList.add(run);

return super.visitRun(run);
}

});

return runList;
}
}

TestFont.docx is in attachment.

Thanks,
Zeljko

Hi Zeljko,

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. This occurs because font is specified via Word 2007 Theme. When font is specified via theme MS Word shows Theme’s name in round brackets (for example “Calibri(body)”). Aspose.Words preserves Themes, but you cannot get Themes properties.

I think, I can suggest you a very simple workaround of this issue. Since DOC format does not support MS Word 2007 Themes, formatting specified in themes is converting to direct formatting. So as a workaround, you can save your DOCX document as DOC, then open DOC file and then get font from this document.

Hope this helps.

Best regards.

Hi,

Thanks for fast response. DOCX file format is XML based format. It is actually collection of compressed XML files. Theme is part of attached docx file (word/theme/theme1.xml, generally theme name is stored in word/_rels/document.xml.rels). I don’t understand way you can read font name from it?

Thanks,
Zeljko

Hi

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your inquiry. Font is defined in theme like this:

<a:minorFont>

<a:latin typeface="Calibri" />

Also, there are defined typefaces for other languages in theme. You can find more information about internal structure of DOCX files and particularly Themes in OOXML specification.

Best regards,