We are using ASPOSE Words v21.7.0 with JDK v1.8 within our Linux machines to generate EMF Images for our text boxes. Within the text box, some of the content have been formatted with “italic” style while using font-family “Liberation-Sans” as common font for the text box. These italic text are not rendering correctly when the text box is converted from HTML to EMF using ASPOSE Words library.
Original HTML: Test Lib Sans Text Box - HTML.zip (775 Bytes)
Excel Document: Test Lib Sans Text Box - Excel.zip (9.0 KB)
HTML(Browser preview) vs EMF comparison: Text not visible clearly for Liberation Sans.png (29.8 KB)
I have tried setting these properties such as anti-aliasing, highQuality rendering, even using higher resolution(but this increases EMF size so not an option to use) in-order to fix the blurry italic but nothing worked for me.
Is their a way to fix this blurry italic text when converting HTML to EMF? This issue is seen in Windows as well as Mac machines with MS Office 365 and 2019 Excel.
@oraspose Unfortunately it is not possible to improve EMF display quality. As an alternative you could try to save textboxes to SVG as another vector image format. Text in SVG image is displayed in better quality in Excel.
Thank you for the information.
I am using ASPOSE Words library v21.7.0 with Java 1.8 within linux machine, to load the HTML file into the ASPOSE Word document and then perform some additional property changes on the document object and finally save the HTML as EMF image. Could you check the below code and suggest if I need to set/update any ImageSaveOptions properties? To render the EMF Image for Italic text without blurriness.
Sample Code:
private void convertToImage() {
try {
byte[] htmlBytes = Files.readAllBytes("Test Lib Sans Text Box - HTML.html");
HtmlLoadOptions options = new HtmlLoadOptions();
Document doc = new Document(htmlBytes, options);
DocumentBuilder builder = new DocumentBuilder(doc);
PageSetup pageSetup = builder.getPageSetup();
//update page properties like size and margin
updatePageSettings(pageSetup);
Section section = doc.getFirstSection();
Body body = section.getBody();
// Update Table Layout properties such as Margin, Padding and Size
TableCollection tables = body.getTables();
if (tables.getCount() == 1) {
Table table = tables.get(0);
// Reset left indent. since table might be shifted left.
table.setLeftIndent(0);
// Need to ensure table has fixed column widths
table.autoFit(AutoFitBehavior.FIXED_COLUMN_WIDTHS);
//update table ROW and CELL Layout
updateTableRowSettings(table);
}
// Save as EMF format
ImageSaveOptions emfOptions = new ImageSaveOptions(SaveFormat.EMF);
emfOptions.setPageSet(new PageSet(0));
doc.save("Test.emf", emfOptions);
} catch(Exception ex) {
System.out.println(ex.getMessage());
}
}
private void updatePageSettings(PageSetup pageSetup) {
double margin = 0;
pageSetup.setLeftMargin(margin);
pageSetup.setRightMargin(margin);
pageSetup.setTopMargin(margin);
pageSetup.setBottomMargin(margin);
pageSetup.setHeaderDistance(0);
pageSetup.setFooterDistance(0);
pageSetup.setPaperSize(PaperSize.CUSTOM);
pageSetup.setPageWidth(180);
pageSetup.setPageHeight(261);
}
private void updateTableProperties(Table table) throws Exception{
// Pass Table Row height and Cell width in points to be set
for (Row row : table.getRows()) {
RowFormat rowFmt = row.getRowFormat();
rowFmt.setAllowBreakAcrossPages(false);
rowFmt.setHeightRule(HeightRule.EXACTLY);
rowFmt.setHeight(261);
for(Cell cell : row.getCells()) {
CellFormat cellFmt = cell.getCellFormat();
cellFmt.setWidth(180);
cellFmt.setTopPadding(0);
cellFmt.setBottomPadding(0);
}
}
}
@oraspose You could add emfOptions.setUseAntiAliasing(true) and emfOptions.setUseHighQualityRendering(true) but it will not affect the text output. Unfortunately it is the best quality you could achieve with EMF output. MS Excel render metafiles by itself probably with the use of GDI+ and this is how the text is displayed.
Thank you for the response. Have a good day.