Please attach a minimal document, and some code that exhibits the issue. Then 
we can probably answer better. But if there is no style directly associated 
with the paragraph or run, it should be getting its style from the default run 
style.

This is found in XWPFStyles.

XWPFStyles styles = doc.getStyles();
XWPFDefaultRunStyle defRun = styles.getDefaultRunStyle();
int size = defRun.getFontSize();

-----Original Message-----
From: apache_user [mailto:p.feizab...@gmail.com] 
Sent: Thursday, January 26, 2017 1:45 AM
To: user@poi.apache.org
Subject: Problem with default font size when reading from docx file

Hello All,

I am trying to read the font size of some runs, but sometimes, I get -1 as the 
font size. I know that it shows the default font size. But I need the actual 
font size. I found a couple of solutions to extract the default font size and 
what I do right now is like the following:

XWPFRun first_run = getFirstRun(paragraph); first_run.getCTR();

using the CTR, I can see something like the following:

<xml-fragment
xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas";
xmlns:cx="http://schemas.microsoft.com/office/drawing/2014/chartex";
xmlns:cx1="http://schemas.microsoft.com/office/drawing/2015/9/8/chartex";
xmlns:cx2="http://schemas.microsoft.com/office/drawing/2015/10/21/chartex";
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006";
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships";
xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math";
xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing";
xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing";
xmlns:w10="urn:schemas-microsoft-com:office:word"
xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main";
xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml";
xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml";
xmlns:w16se="http://schemas.microsoft.com/office/word/2015/wordml/symex";
xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup";
xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk";
xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml";
xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape";><w:rFonts
w:ascii="Arial" w:hAnsi="Arial" w:cs="Arial"/><w:b/><w:sz w:val="20"/><w:szCs 
w:val="20"/></xml-fragment> first run: Manage and font is: 10 new try: 
<xml-fragment 
xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas";
xmlns:cx="http://schemas.microsoft.com/office/drawing/2014/chartex";
xmlns:cx1="http://schemas.microsoft.com/office/drawing/2015/9/8/chartex";
xmlns:cx2="http://schemas.microsoft.com/office/drawing/2015/10/21/chartex";
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006";
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships";
xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math";
xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing";
xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing";
xmlns:w10="urn:schemas-microsoft-com:office:word"
xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main";
xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml";
xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml";
xmlns:w16se="http://schemas.microsoft.com/office/word/2015/wordml/symex";
xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup";
xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk";
xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml";
xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape";><w:rFonts
w:ascii="Arial" w:hAnsi="Arial" w:cs="Arial"/><w:b/><w:sz w:val="20"/><w:szCs 
w:val="20"/></xml-fragment>

The last line is what shows the font information. Right? But the point in my 
case is that, that is not true! The font size of the text in the .docx file is 
12, getFontSize() returns -1 (that is it uses the default font), and the xml 
part says its 10!

In the meantime, I tried use getStyleID() for the paragraph and getStyles() for 
the document. But it didn't help as the paragraph had no style and
getStyleID() returned null.

If it helps, I'm reading the data from cells of a table and I know that the 
paragraphs and runs are extracted correctly.

Can anybody help me?

Thanks in advance,




--
View this message in context: 
http://apache-poi.1045710.n5.nabble.com/Problem-with-default-font-size-when-reading-from-docx-file-tp5726353.html
Sent from the POI - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@poi.apache.org For additional 
commands, e-mail: user-h...@poi.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@poi.apache.org
For additional commands, e-mail: user-h...@poi.apache.org

Reply via email to