I am a newbie for docx4j and for my application I need to identify the sentences (or paragraph) is in bold. I cannot figure out how to get the font style details for a particular paragraph. Any help is appreciated
-
Is the bold directly applied formatting, or in your styles, or both? – JasonPlutext Aug 28 '14 at 09:34
-
It is both JasonPlutext – Nadeeshaan Aug 28 '14 at 10:02
1 Answers
You need to look for w:rPr/w:b, that is, for the bold tag within the run properties element.
This can be in a run (w:r) within a paragraph (w:p), or within a style referenced from the run's style (w:rPr/w:rStyle if present) or the paragraph's style (w:p/w:pPr/w:pStyle, for example Heading1).
Since styles can be based on other styles, you need to climb the style hierarchy to check for bold.
The easiest way to do what you want is to mimic the PDF output; see https://github.com/plutext/docx4j/blob/master/src/main/java/org/docx4j/convert/out/fo/XsltFOFunctions.java
line 242 for the PPr level stuff
line 776 for the RPr level stuff
I assume you can work out how to visit each paragraph (see GettingStarted); probably you ought to traverse in Java (as opposed to via XSLT).

- 15,352
- 4
- 44
- 84