Free Support Forum - aspose.com

Font size is changing when converting from Html to Rtf


#1

Hi,
When I’m converting from html to RTF the font size is decreasing in RTF document.
The following code i have used for conversion

        String htmlString="<p><span style=\"font-family: Arial; font-size: 10px;\">Trademark logo ® for testing in the ™ templates.</span></p>";
		
        HtmlLoadOptions options = new HtmlLoadOptions();
        options.setLoadFormat(LoadFormat.HTML);
        options.setPreserveIncludePictureField(true);
        ByteArrayInputStream is = new ByteArrayInputStream(htmlString.getBytes(Charset.forName("UTF-8")));
    	Document doc = new Document(is, options);

    	ByteArrayOutputStream os = new ByteArrayOutputStream();
    	com.aspose.words.SaveOptions saveOptions = com.aspose.words.SaveOptions.createSaveOptions(SaveFormat.RTF);
    	saveOptions.setSaveFormat(SaveFormat.RTF);
    	doc.save(os, saveOptions);
    	String rtfString = new String(os.toByteArray(), StandardCharsets.UTF_8);

In the code i gave 10px font size for html and I’m sending you the output file in that you can see font size change other than 10px.InsertDocumentAtReplace_out.zip (10.4 KB)


#2

@dineshreddydepa

Please note that Aspose.Words mimics the behavior of MS Word. If you open the same HTML in MS Word and save it to RTF, you will get the same output.

Please change the px to pt in font style ‘font-size: 10pt’ to get the desired output.