我用过Free Spire.PDF for Java来将html转换为PDF,代码操作简单,转换效果不错,可以一试。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) { //定义需要转换的HTML String url = "https://www.e-iceblue.cn/"; String fileName = "Result.pdf"; //设置插件本地地址 String pluginPath = "D:/Qt/plugins_32"; HtmlConverter.setPluginPath(pluginPath); //转换到PDF并设置PDF尺寸 HtmlConverter.convert(url, fileName, true, 1000000, new Size(600f, 900f), new PdfMargins(0)); } }在运行代码前,需要下载您系统适用的插件包到本地文件夹。
我用过Free Spire.PDF for Java来将html转换为PDF,代码操作简单,转换效果不错,可以一试。
在运行代码前,需要下载您系统适用的插件包到本地文件夹。