Free Support Forum -

Convert HTML file to Microsoft Word Document in Java with Aspose.Words REST API

I’m trying to find the ability to convert an HTML file to a Document using the Aspose Cloud Java SDK. I’ve found the ability do this for PDFs and the ability to convert a live web page to a Document, but not a simple HTML file. Is this possible, or is there a work around available to do this that I can’t find?

Hi Ryan,

Thanks for your inquiry. Yes, you can convert html file to Word document. Please check the convert resource and following article. You just need to change the input file name output file format as shown in following code snippet. Hope this helps you.

Convert Word to other File Formats without using the Cloud Storage

//Instantiate Aspose Words API SDK<o:p></o:p>
WordsApi wordsApi = new WordsApi(apiKey, appSID,true);<o:p></o:p>
//set input file name<o:p></o:p>
String fileName = “input.html”;<o:p></o:p>
File file = new File(WordFormatConverterUsingCloudStorageExample.class.getResource("/" + fileName).toURI());<o:p></o:p>
//set the desire output format<o:p></o:p>
String format = “docx”;<o:p></o:p>
String outPath = “”;<o:p></o:p>

Hi Tahir,

Thanks for the response. I’m trying this approach and getting an error on the PutConvertDocument operation - “MIME multipart content is not supported by the operation.” I’ve attached my HTML file and have a code snippet below, if you have any insights. Thanks!

WordsApi wordsApi = new WordsApi(apiKey, appSID, true);

File file = new File("/Users/Ryan/Documents/conversion.html");

//set the desire output format
String format = “docx”;
String outPath = “”;

//invoke Aspose.Words Cloud SDK API to convert words document to required format using file
ResponseMessage apiResponse = wordsApi.PutConvertDocument(format, outPath, file);

if (apiResponse != null && apiResponse.getInputStream() != null) {
//save api response to file
final Path destination = Paths.get("/Users/Ryan/Documents/conversion.docx");
Files.copy(apiResponse.getInputStream(), destination, StandardCopyOption.REPLACE_EXISTING);
Hi Ryan,

Thanks for your inquiry. Please get the examples from Aspose.Words for Cloud examples repository at GitHub and use the to convert your html to Docx. We have attached the output document with this post for your kind reference.