Thanks for your request. I cannot reproduce the problem on my side using the latest version of Aspose.Words for Java (4.0.2). I use the following code for testing:
Document doc = new Document("C:\\Temp\\in.doc");
System.out.print(doc.getSections().get(0).getBody().getFirstParagraph().getListFormat().getListLevel().getFont().getSize());
This code returns 18, as expected.
The in.doc is attached.
Best regards,
Hi, thank you for a reply.
I have another problem. I need to change the size of list item number fonts.
I’m using following code:
Document document = new Document("E:\TEST.doc");
NodeCollection paragraphs = document.getChildNodes(NodeType.PARAGRAPH, true);
List resized = new ArrayList();
for (Paragraph paragraph: paragraphs)
{
if (paragraph.getListFormat().isListItem())
{
double listLevelFontSize = paragraph.getListFormat().getListLevel().getFont().getSize();
double paraBreakFontSize = paragraph.getParagraphBreakFont().getSize();
Font font = null;
if (listLevelFontSize == paraBreakFontSize)
{
font = paragraph.getListFormat().getListLevel().getFont();
}
else
{
font = paragraph.getParagraphBreakFont();
}
if (!resized.contains(font))
{
resizeFont(font, -1.0);
resized.add(font);
}
}
}
private static void resizeFont(Font font, double value) throws Exception
{
if (font != null && font.getSize() + value> 0)
{
font.setSize(font.getSize() + value);
}
}
In the result, the font of list item numbers is ok. However, the font in the part of third point has also changed. Can you help with this ?
I’m attaching document for testing.
Thanks for your request. This can occur because text in your document consists of multiple Runs. Usually this occurs when you edit document multiple times in MS Word.
There is joinRunsWithSameFormatting method, which concatenates runs with same formatting. Please try using the following code:
Document doc = new Document("C:\\Temp\\TEST.doc");
doc.joinRunsWithSameFormatting();
NodeCollection <Paragraph> paragraphs = doc.getChildNodes(NodeType.PARAGRAPH, true);
for (Paragraph paragraph: paragraphs)
{
if (paragraph.getListFormat().isListItem())
{
paragraph.getParagraphBreakFont().setSize(18);
}
}
doc.save("C:\\Temp\\out.doc");
Hi,
thank you for a reply. Your solution works but not in every case.
I’am attaching another document. This time, whole text in point 3 has been resized.
The problem is that i need to decrease font size (for example by 1 pt) in whole document.
So I need get the font size and then set the size decreased by 1 pt.
Thank you for additional information. I think you can achieve this using DocumentVisitor. To change font size you can try using FontSizeChanger class attached here.
Please see the following code:
Document document = new Document("TEST_2.doc");
FontSizeChanger changer = new FontSizeChanger(4);
document.Accept(changer);
document.Save("out.doc");
Please let me know in case of any issues. I will be glad to help you.
Best regards,
Hi,
thank you for reply.
I’ve already tried this approach. Have a look at: FitToPages
The approach with DocumentVisitor is not good because it decreases font too much.
For example:
TEST.doc is source document
TEST_res.doc is document in which I decreased font by 2 pt using DocumentVisitor and some of paragraphs have font decreased twice
I’m trying to implement it in other way, without using DocumentVisitor, everything works fine except the font in list numbers