Html content not showing proper in word and pdf in java

I have added ckEditor(frontend html content creator tool) in ui side the html content showing proper in ckEditor ui side but same html content not reflect while try to print in pdf/word

@kalpeshAspose1997 Could you please attach your input HTML document and provide code you use for conversion from HTML to Word/Pdf? We will check the issue and provide you more information.
Also, please note, HTML and MS Word documents are quite different and it is difficult and sometimes impossible to provide 100% fidelity after conversion from one format to another.

@alexey.noskov

we used following method to print html content in word/pdf

document.getMailMerge().setFieldMergingCallback(new CustomFieldMergingCallback());

html content code :
htmlContent.zip (617 Bytes)

expected: not 100% accurate, how can we do it better ?

output of pdf:
attached output of html content

@kalpeshAspose1997 The image definition in your HTML is the following:

<img src="http://localhost:8080/rest/attachments/viewAttachment/d076bb53f1fabb4bb44a3ebf5c6c5edc0d5e6d1fa06bd567dbb031fdde667b1f" class="ngx-editor-image" data-attachment-id="429">

But, ngx-editor-image class, which defines the image formatting is not available in your HTML snippet, so expectedly Aspose.Words uses the original image size when you insert the HTML into the document.

so can you pls send me the example of add external css for html content using java,
Thank you team.

@kalpeshAspose1997 You should define the required styles in the HTML. For example:

<html>
<head>
    <style type="text/css">
        .myclass {
            width: 100pt;
            height: 100pt;
        }
    </style>
</head>
<body>
    <img src="C:/Temp/test.png" class="myclass" />
</body>
</html>

Or reference the external CSS in your HTML, like this:
test.css

.myclass {
    width: 100pt;
    height: 100pt;
}

And here is HTML:

<html>
<head>
    <link rel="stylesheet" href="C:/Temp/test.css">
</head>
<body>
    <img src="C:/Temp/test.png" class="myclass" />
</body>
</html>
1 Like