When an HTML source file contains a table which has text formatted to be rotated vertically, the format is ignored when the HTML is inserted via DocumentBuilder.
To reproduce this behavior:
- Copy the attached HTML source file “VerticalText.html” to the file system…
- Use the sample code below to generate a new Word document which inserts the given HTML via the DocumentBuilder.insertHtml API.
- Examine the generated document and notice that the cell with vertical text has horizontal alignment.
Notes:
- If you preview the HTML in any major browser, you can see it will show a text heading to be vertically formatted
- It’s clear that Aspose Words supports vertical text in cells via the TextOrientation class, but for some reason, this is not applied when the insertHtml API is used.
- The sample code was tested on the latest Aspose Words version 17.7.
Sample Code:
public static void verticalTextHtml() {
// add full path as necessary
final String htmlSrc = "VerticalText.html";
try {
// create new blank document
Document wdDoc = new Document();
DocumentBuilder builder = new DocumentBuilder(wdDoc);
// load the html
final String html = new String(Files.readAllBytes(Paths.get(htmlSrc)));
// add the paragraph to the document
Paragraph para = builder.insertParagraph();
builder.moveTo(para);
// insert the HTML into the doc - keep HTML formatting intact
builder.insertHtml(html, false);
wdDoc.save(htmlSrc.replace(".html", ".docx"));
System.out.println("Saved Document: " + htmlSrc.replace(".html", ".docx"));
} catch (Exception ex) {
ex.printStackTrace();
}
}
Attachment:
VerticalText.zip (3.2 KB)
Thanks.