我遇到了一些问题,使用Java将HTML转换为图像。我正在使用html2image [java]。
它可以创建图像,但问题是它只能在HTML的一小部分上创建图像。我该如何使其创建整个HTML的图像。谢谢。
这是我的代码:
import gui.ava.html.image.generator.HtmlImageGenerator;
import java.io.File;
public class test {
public static void main(String[] args) {
HtmlImageGenerator imageGenerator = new HtmlImageGenerator();
String uri = new File("C:\\cover.html").toURI().toString();
imageGenerator.loadUrl(uri);
imageGenerator.saveAsImage("hello-world.png");
imageGenerator.saveAsHtmlWithMap("hello-world.html", "hello-world.png");
}
}
我使用saveAsHtmlWithMap来保存HTML文件。由程序写入硬盘的HTML文件也很小。
以下是cover.thml的HTML代码:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="***">
<head>
<title></title>
<meta charset="utf-8"/>
<meta name="viewport" content="width=1200, height=1200"/>
<link rel="stylesheet" type="text/css" href="main.css"/>
</head>
<body id="cover_page">
<nav id="cover" >
<ol>
<li id="nav1">
<a>cover</a>
</li>
</ol>
</nav>
</body>
</html>