How to get font size of paragraph from docx document using apache POI?

Viewed 2574

I have a MS-Word document in docx format. I want to get font size of each paragraph or line. I tried looking similar approach used here for docx file on apache POI documentation page but could not found one.

I tried this approach but it is giving -1 as font size and font-name as null.

File file = new File(fileName);
FileInputStream fis = new FileInputStream(file.getAbsolutePath());

XWPFDocument document = new XWPFDocument(fis);
List<XWPFParagraph> paragraphs = document.getParagraphs();

System.out.println("Total no of paragraph in Docx : "+paragraphs.size());
for (XWPFParagraph para : paragraphs) {
    XWPFStyle style = document.getStyles().getStyle(para.getStyleID());
    System.out.println(para.getText());
    int pos = 0;
    for (XWPFRun run : para.getRuns()) {
      System.out.println("Current run IsBold : " + run.isBold());
      System.out.println("Current run IsItalic : " + run.isItalic());
      System.out.println("Current Font Size : " + run.getFontSize());
      System.out.println("Current Font Name : " + run.getFontName());
    }
  }
  fis.close();

Update: I found this, but could not manage to get font size.

Thanks in advance.

1 Answers
Related