Small Caps font was not applying for the text why in Aspose.words?

private static String applyFont(String text, boolean smallCaps) throws Exception {
    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);

    Font font = builder.getFont();
    font.setSmallCaps(smallCaps);

    builder.write(text);

    // Save the document to a string
    String output = doc.getText();
    System.out.println("OutputText: "+output);
    return output;
}

@AAddd

The issue you’re experiencing with the Small Caps font not applying correctly in Aspose.Words may be due to how the font properties are being set in your code.

In your implementation, you are setting the smallCaps property on the Font object, but it is important to ensure that the text is being added to the document in a way that respects this formatting. Here’s a refined version of your method that demonstrates how to apply the Small Caps formatting correctly:

private static String applyFont(String text, boolean smallCaps) throws Exception {
    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);

    // Set the font properties
    Font font = builder.getFont();
    font.setSmallCaps(smallCaps); // Apply Small Caps formatting

    // Write the text with the specified font settings
    builder.writeln(text); // Use writeln to ensure the text is added correctly

    // Save the document to a string
    String output = doc.getText();
    System.out.println("OutputText: " + output);
    return output;
}

Key Points:

  1. Use writeln: This method ensures that the text is added to the document with the current font settings applied.
  2. Check Font Availability: Ensure that the font you are using supports Small Caps. Not all fonts have this feature, and if the font does not support it, the formatting will not be applied.

If you continue to face issues, consider checking the font settings in your environment or testing with a different font that is known to support Small Caps.

Feel free to reach out if you have any further questions or need additional assistance!

@AAddd Simple text cannot be small caps formatted. This type of formatting is applied in the output document, the same as you cannot see font color applied to text when output the content in simple text.
So to see small caps formatting, you should save the output to DOCX for example.