Convert to HTML with advanced options

To convert documents to HTML with advanced options using GroupDocs.Conversion for Java, you can utilize the WebConvertOptions class. This class provides various properties to customize the HTML output according to your requirements:

OptionDescription
setUsePdf()If true, the input firstly is converted to PDF and after that to desired format.
setFixedLayout()If true fixed layout will be used e.g. absolutely positioned html elements
Default: true.
setFixedLayoutShowBorders()Show page borders when converting to fixed layout. Default: true.
setZoom()Specifies the zoom level in percentage. Default: 100.

The following code snippet shows how to convert to HTML with advanced options:

import com.groupdocs.conversion.Converter;
import com.groupdocs.conversion.options.convert.WebConvertOptions;
import com.groupdocs.conversion.options.load.WordProcessingLoadOptions;

public class ConvertToHtmlWithAdvancedOptions {
    public static void convert() {
        // Instantiate the WordProcessingLoadOptions
        WordProcessingLoadOptions loadOptions = new WordProcessingLoadOptions();
        loadOptions.setPassword("12345");

        // Initialize the converter with the source document
        try(Converter converter = new Converter("password_protected.docx", () -> loadOptions)) {
            // Instantiate the WebConvertOptions
            WebConvertOptions options = new WebConvertOptions();
            options.setUsePdf(true); // Convert via PDF to maintain layout
            options.setFixedLayout(true); // Use fixed layout
            options.setFixedLayoutShowBorders(true); // Show borders in fixed layout
            options.setZoom(100); // Set zoom level to 100%

            // Convert to HTML with the specified options
            converter.convert("converted_with_options.html", options);
        }
    }

    public static void main(String[] args){
        convert();
    }
}

password_protected.docx is sample file used in this example. Click here to download it.

converted_with_options.html is converted HTML document. Click here to download it.

In this example, the Converter class is initialized with the source document. The WebConvertOptions are then configured to convert the document via PDF, use a fixed layout with borders, and set the zoom level to 100%. Finally, the convert method is called to perform the conversion with the specified options.

By utilizing these options, you can effectively control the HTML conversion process to meet your specific needs.