Cannot convert from HTML to MHTML in Java

Hi guys,

I am using aspose-html (version 25.4) and trying to convert my .html file (included images) to .mhtml file. However, the error shows “Path is empty”. I am sure that the html file is existing with correct path. Can you please help to show this error?
Below is my code
Screenshot 2025-04-16 at 18.08.02.jpg (115.5 KB)

@minhnguyen63

It seems you are encountering a “Path is empty” error while trying to convert an HTML file to MHTML using Aspose.HTML in Java. This issue typically arises when the file path provided to the HTMLDocument constructor is incorrect or not properly set.

Here’s a sample code snippet that demonstrates how to correctly convert an HTML file to MHTML format:

import java.io.IOException;
import com.aspose.html.HTMLDocument;
import com.aspose.html.converters.Converter;
import com.aspose.html.saving.MHTMLSaveOptions;

public class HTMLToMHTMLConverter {
    public static void main(String[] args) {
        try {
            // Specify the path to your HTML file
            String inputFilePath = "path/to/your/input.html"; // Update this path
            // Specify the output path for the MHTML file
            String outputFilePath = "path/to/your/output.mht"; // Update this path

            // Load the HTML document
            HTMLDocument htmlDocument = new HTMLDocument(inputFilePath);

            // Initialize MHTML save options
            MHTMLSaveOptions options = new MHTMLSaveOptions();
            options.getResourceHandlingOptions().setMaxHandlingDepth(1);

            // Convert HTML to MHTML
            Converter.convertHTML(htmlDocument, options, outputFilePath);
            System.out.println("Conversion successful! MHTML file created at: " + outputFilePath);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Key Points to Check:

  1. File Paths: Ensure that the paths for both the input HTML file and the output MHTML file are correctly specified. They should point to valid locations on your filesystem.
  2. File Existence: Verify that the HTML file exists at the specified path before running the conversion.
  3. Permissions: Make sure that your application has the necessary permissions to read the input file and write to the output location.

If you continue to face issues, please double-check the paths and ensure that the files are accessible. If the problem persists, consider providing additional details about your environment or any other error messages you may be receiving.

I tried the code above but it didn’t work. And I am sure that the html file is existing in correct path
Screenshot 2025-04-16 at 18.22.16.jpg (111.7 KB)

HTML file:
Screenshot 2025-04-16 at 18.24.19.png (75.3 KB)

@minhnguyen63

Can you please share your sample HTML in .zip file with us? We will test the scenario in our environment and address it accordingly.

Hi asad.ali,

I send you the html in .zip file. Just note that: there are some images which are included in the .html file

test.zip (4.8 MB)

@minhnguyen63

What about the images included in the .zip? We have checked by opening the HTML file in Chrome Browser and it is not displaying any of those images. Do we need to update the image paths in HTML file before trying conversion?

Hi @asad.ali , yeah, I think so. We need to update the images path before opening the html file. Because I used extent report to attach the images into .html file. Please

@minhnguyen63

Can you please also share what kind of image path the HTML has at your side? Are images placed in the same directory or they are accessed using network?