Aspose API is giving Wrong Font Size

Hi,

I am using Aspose API to get the font size of paragraph break character used in paragraph table in primary header and found that API is not giving correct result. From Microsoft Word UI, I can see font size of Header as 10 while ASPOSE API is returning me font size 12. Kindly find the sample code below and look into the issue. Please let me know if you need more information.

Sample test Code:
--------------------------------

public void test() throws Exception {
    Document doc = new Document("Sample Document1.docx");
    Section sec0 = doc.getSections().get(0);
    Section lastSec = null;
    if (doc.getSections().getCount() > 1)
        lastSec = doc.getSections().get(doc.getSections().getCount() - 1);

    HeaderFooter hf = sec0.getHeadersFooters().getByHeaderFooterType(HeaderFooterType.HEADER_PRIMARY);
    System.out.println(hf.isHeader());
    System.out.println(hf.getText());

    NodeCollection hfChildren = hf.getChildNodes();

    for (int i = 0; i < hfChildren.getCount(); i++) {

        Node child = hfChildren.get(i);

        if (child.getNodeType() == NodeType.PARAGRAPH) {
            Paragraph para = (Paragraph)child;
            com.aspose.words.Font font = para.getParagraphBreakFont();
            System.out.println("Font Size: " + font.getSize());
            System.out.println("Font name: " + font.getName());
            System.out.println("Font bold: " + font.getBold());
            System.out.println("Font Style Name: " + font.getStyle().getName());
            System.out.println("Font Base Style Name: " + font.getStyle().getBaseStyleName());
        }
    }
}

------------------------------------------

Output:
Font Size: 12.0
Font name: Times New Roman
Font bold: false
Font Style Name: Default Paragraph Font
Font Base Style Name:

Please find the sample document and snapshot in the attachment.
Please help me resolving this problem.

Thanks
Manisha

Hi Manisha,

Thanks for your inquiry. In your case, you can get the correct size using following code:

Document doc = new Document(getMyDir() + "Sample+Document1.docx");
HeaderFooter primaryHeader = doc.getFirstSection().getHeadersFooters().getByHeaderFooterType(HeaderFooterType.HEADER_PRIMARY);
Paragraph firstPara = primaryHeader.getFirstParagraph();
System.out.println(firstPara.getParagraphBreakFont().getSizeBi());

Hope, this helps.

Best regards,

Hi,

I ran following code to get the font size of paragraph break character in Header_Primary and noticed some peculiar behaviour that I want to understand.

Document doc = new Document(getMyDir() + "Sample+Document1.docx");
HeaderFooter primaryHeader = doc.getFirstSection().getHeadersFooters().getByHeaderFooterType(HeaderFooterTyp> e.HEADER_PRIMARY);
Paragraph firstPara = primaryHeader.getFirstParagraph();
System.out.println(firstPara.getParagraphBreakFont().getSizeBi());

If font size is explicitly specified at style “Default Paragraph Font” (DPF) in style.xml then this code prints that size but if size is not defined at DPF then it looks for size defines at style “Normal”.

Questions:

1. Why Normal size is considered when Default Paragraph Font is not based upon Normal?
2. Is this the expected behaviour?
3. Does MS Word also behave same?
4. Can we cross check this size in MS Word UI?

Please help me in understanding this behaviour.

Thanks
Manisha

Hi Manisha,

Thanks for your inquiry. The behavior is different because the paragraph break has two different Locale IDs assigned to it for different ‘characters group’. Please see the following code for example:

Document doc = new Document(getMyDir() + "Sample+Document1.docx");
HeaderFooter primaryHeader = doc.getFirstSection().getHeadersFooters().getByHeaderFooterType(HeaderFooterType.HEADER_PRIMARY);
Paragraph firstPara = primaryHeader.getFirstParagraph();
System.out.println(firstPara.getParagraphBreakFont().getLocaleId()); // English - United States
System.out.println(firstPara.getParagraphBreakFont().getLocaleIdBi()); // Arabic - Saudi Arabia

Best regards,