poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bhaarat Sharma <bhaara...@gmail.com>
Subject How to correctly read the font size of each word in a word document
Date Wed, 10 Jul 2013 21:12:06 GMT
I am trying to find out whether there exist anything in the word document
that has a font of 2. However, I have not been able to do this. To begin
with, I've tried to read the font of each word in a sample word document
that only has one line and 7 words (file attached). I am not getting the
correct results.

Here is my code:

HWPFDocument doc = new HWPFDocument (fileStream);
WordExtractor we = new WordExtractor(doc);
Range range = doc.getRange()
String[] paragraphs = we.getParagraphText();
for (int i = 0; i < 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())

However, the above code always doubles the font size. i.e. if the actual
font size in the document is 12 then it outputs 24 and if actual font is 8
then it outputs 16.

Is this the correct way to read font size from a word document ??


View raw message