Java convert HTML to PDF

This article will show you how to convert HTML to PDF in Java applications. Ensure that you are using Spire.PDF for Java v3.6.6 or above. You could get the new plugin from the download file directly: windows-x86.zip, windows-x64.zip, macosx_x64.zip, and linux_x64.zip and then unzip it.

import com.spire.pdf.graphics.PdfMargins;
import com.spire.pdf.htmlconverter.qt.HtmlConverter;
import com.spire.pdf.htmlconverter.qt.Size;

public class HtmltoPDF {
    public static void main(String[] args) {
        //define the HTML link and result PDF 
        String url = "https://www.e-iceblue.com/";
        String fileName = "Result.pdf";
        //Set the plugin path
        String pluginPath = "D:/Qt/plugins_32";
        HtmlConverter.setPluginPath(pluginPath);
        //convert HTML to PDF and set the size of the result PDF page
        HtmlConverter.convert(url, fileName, true, 1000000, new Size(600f, 900f), new PdfMargins(0));
    }
}

Please check the effective screenshot of the PDF as below:

Java convert HTML to PDF