Free Support Forum - aspose.com

Insert HTML String in Word Document & Retain Font Size of Superscript Text using Java Code

Hello,

This may be the same issue as this existing issue. However, we do not have access to the sample file (so we can’t check) and additionally this is for Aspose Words for Java.

The font size for Text formatted with superscript increases from an HTML import. For example, suppose the HTML specifies: <font style="font-size:16pt;">Test Content <sup>(2)</sup></font>
If this HTML is imported into a Document, the font size for the Superscript text “(2)” increases from 16 pts. to 20 pts.

This behavior can be seen in the latest Aspose Words for Java version 21.3, the attached SuperscriptSize.html file and the following Java code:

final String htmlSrc = [PATH] + "SuperscriptSize.html";

Document wdDoc = new Document();
DocumentBuilder builder = new DocumentBuilder(wdDoc);
builder.moveToDocumentEnd();
    
// load & insert the HTML into the doc
String html = new String(Files.readAllBytes(Paths.get(htmlSrc)), "UTF-8");
builder.insertHtml(html, false);
    
final String newDoc = htmlSrc.replace(".html", ".docx");
Files.deleteIfExists(Paths.get(newDoc));
wdDoc.save(newDoc);
    
System.out.println("Saved Document:  " + newDoc);

Key Observations:

  1. Running the above code under Words 21.3, should produce a file similar to the attached SuperscriptSize.docx file.
  2. If you open the generated DOCX file in Word - examine the font sizes of the all the text that is in Superscript.
    You should see that the font size increases from the font size that is assigned to the text in the cells of the table.
    For example, the last cell in the table is expected to have an 16 point font - but the text with superscript has a 20 pt. font.
  3. We’ve included a screen-shot of how the text with superscript has an increased font size in the attached SuperscriptSize-Word.png file.
  4. If you render the HTML in a Browser and examine the font sizes of the superscript text, it does not increase from the font size assigned to the cell.

Environment Details:

  • Aspose Words for Java 21.3
  • Java version 1.8.0_211
  • Windows 10 OS (but also reproducible under Linux).

File description in the SuperscriptSize.zip (35.9 KB) attachment contains:

  • SuperscriptSize.html: HTML file to be used by the code above.
  • SuperscriptSize.docx: DOCX file generated after running the code above on our environment.
  • SuperscriptSize-Word.png: Screen-shot of the Font dialog from Word with the superscript text selected.

Thank you!

@oraspose,

For the sake of correction, we have logged this problem in our issue tracking system. The ID of this issue is WORDSNET-22100. We will further look into the details of this problem and will keep you updated on the status of correction. We apologize for your inconvenience.