Hi, I have some problem with text capitalization. In attached document you can see that whole paragraph is in upper case, but when I iterate through that paragraph and prints text, it prints some of them in lower case. Here is code for test:
InputStream inputStream = getClass().getClassLoader()
.getResourceAsStream("invalidTextCase.doc");
Document document = new Document(inputStream);
Section section = document.getFirstSection();
Body body = section.getBody();
Paragraphs paragraphs = body.getParagraphs();
Paragraph paragraph = paragraphs.get(16);
Runs runs = paragraph.getRuns();
for (int i = 0; i < runs.getCount(); i++) {
System.out.println("Index: " + i + " run text: " + runs.get(i).getText()); //second run is in lowercase
}
Thanks, Ivica.
Hi
Thanks for your request. This occurs because AllCaps is set to true. You can try using the following code.
for (int i = 0; i < paragraph.getRuns().getCount(); i++)
{
String text = paragraph.getRuns().get(i).getText();
if (paragraph.getRuns().get(i).getFont().getAllCaps())
text = text.toUpperCase();
System.out.println("Index: " + i + " run text: " + text);
}
Best regards.
Ok, but allCaps on first run is set to false and all text in it is in upper case. Can you explain to me a way this is functioning little more detailed.
Thanks, Ivica.
Hi
Thanks for your inquiry. You can write text in Upper case ( Press CapsLock and write text). Also you can write regular text (in lower case) then select this text, right click and select Font, then set checkbox “All caps”.
Best regards.