Greetings,
I’m having an issue retrieving the font/style properties of a paragraph. In my situation, I’m creating a new dynamically-created Document to be inserted into an existing parent Document at a merge field. The problem is, when I insert my new sub-document, it’s taking on the complete default Word Style (Style: “Normal”, Font: Calibri, Size: 11pt, Line Spacing: 10pt) rather than inheriting the font properties of paragraph being inserted into (Style: “Normal”, Font: Arial, Size: 12pt, Line Spacing: 0pt). This happens regardless of using ImportFormatMode.USE_DESTINATION_STYLES or ImportFormatMode.KEEP_SOURCE_FORMATTING during the sub-doc insertion.
Before doing a builder.write, I try to grab the font properties from the parent at the merge field location and use those properties when writing to the sub-doc.
Boolean foundMrgFld = parentDocBuilder.moveToMergeField(myMergeField);
if (foundMrgFld) {
Node insertAfterNode = parentDocBuilder.getCurrentParagraph();
if (insertAfterNode.getNodeType() == (NodeType.PARAGRAPH)) {
Paragraph para = (Paragraph)insertAfterNode;Style insertStyle = para.getParagraphFormat().getStyle();subDocBuilder.getParagraphFormat().setStyle(insertStyle);…
subDocBuilder.write(…
}
}
In this case, even though the insertAfterNode is 12pt Arial, the insertStyle returned is the default “Normal” Style 11pt Calibri (confirmed via insertStyle.getFont().getName() / getSize() / etc while debugging). It seems perhaps the issue is because the paragraph Style is Normal" in both cases, even though a custom font and size have been set in the parent document. Can anyone provide a quick example of how to return the actual font properties of a Paragraph and not just the Style’s font properties?
I really can’t attach examples because of the sheer volume of code that went into generating the dynamic child document, but potentially someone can take a basic Word document and easily recreate this. Just use custom fonts/size but keep the Style as default, then test retrieving the Style through Aspose at that paragraph and checking the font/size it returns. That should be sufficient to test.
Thanks for any help.