Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.
Wed Feb 03, 2021 4:37 pm
Please advice on getting the font size of the paragraph in docx file. We tried different fonts but getting 11 always. Here is the code:
Document document = new Document();
document.loadFromFile("FontSize.docx");
SectionCollection sectionCollection = document.getSections();
for(int i=0; i < sectionCollection.getCount(); i++) {
ParagraphCollection paraCollection = sectionCollection.get(i).getParagraphs();
for(int j=0; j < paraCollection.getCount(); j++) {
Paragraph p = paraCollection.get(j);
System.out.println(p.getStyle().getCharacterFormat().getFontSize()); // This always gives 11
}
}
-
pr20080798
-
- Posts: 148
- Joined: Wed Jan 20, 2021 1:15 pm
Thu Feb 04, 2021 3:29 am
Hello,
Thanks for your inquiry.
Please refer to the following code to get the font size. If there are any questions, please provide your input file for further investigation.
- Code: Select all
Document document = new Document();
document.loadFromFile("test.docx");
SectionCollection sectionCollection = document.getSections();
for(int i=0; i < sectionCollection.getCount(); i++) {
ParagraphCollection paraCollection = sectionCollection.get(i).getParagraphs();
for(int j=0; j < paraCollection.getCount(); j++) {
Paragraph p = paraCollection.get(j);
DocumentObjectCollection childObjects = p.getChildObjects();
System.out.println();
for (Object obj:childObjects) {
DocumentObject documentObject = (DocumentObject) obj;
if(documentObject.getDocumentObjectType()==DocumentObjectType.Text_Range){
TextRange textRange = (TextRange) documentObject;
System.out.println(textRange.getCharacterFormat().getFontSize());
break;
}
}
}
}
Sincerely,
Brian
E-iceblue support team
-
Brian.Li
-
- Posts: 1271
- Joined: Mon Oct 19, 2020 3:04 am
Mon Feb 22, 2021 4:22 am
Thank you Brian. This is exactly what we want.
Thanks for the solution.
-
pr20080798
-
- Posts: 148
- Joined: Wed Jan 20, 2021 1:15 pm
Mon Feb 22, 2021 7:26 am
You are welcome.
If you encounter any issues related to our products in the future, please feel free to contact us.
Sincerely,
Brian
E-iceblue support team
-
Brian.Li
-
- Posts: 1271
- Joined: Mon Oct 19, 2020 3:04 am