java - How to read font size of each word in a word document using POI? -


i trying find out whether there exist in word document has font of 2. however, have not been able this. begin with, i've tried read font of each word in sample word document has 1 line , 7 words. not getting correct results.

here code:

hwpfdocument doc = new hwpfdocument (filestream); wordextractor = new wordextractor(doc); range range = doc.getrange() string[] paragraphs = we.getparagraphtext(); (int = 0; < paragraphs.length; i++) {   paragraph pr = range.getparagraph(i);   int k = 0   while (true) {      characterrun run = pr.getcharacterrun(k++);      system.out.println("color: " + run.getcolor());      system.out.println("font: " + run.getfontname());      system.out.println("font size: " + run.getfontsize());      if (run.getendoffset() == pr.getendoffset())        break;   } } 

however, above code doubles font size. i.e. if actual font size in document 12 outputs 24 , if actual font 8 outputs 16.

is correct way read font size word document ??

yes, that's correct way; measurement in half points.

in docx, you'd have like:

<w:rpr>    <w:sz w:val="28" />   </w:rpr> 

ecma 376 spec on @sz defines unit st_hpsmeasure (measurement in half-points)

its same binary doc format, hwpf supports. if @ [ms-doc], you'll see specifies size of text in half-points.


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -