html转图片网页截屏(一),java库cssbox

引入依赖包

<dependency>
<groupId>net.sf.cssbox</groupId>
<artifactId>cssbox</artifactId>
<version>4.14</version>
</dependency>


案例:

public static void main(String[] args) throws Exception {
ImageRenderer render = new ImageRenderer();
render.setWindowSize(new Dimension(800, 1000), false);
System.out.println("kaishi");
String url = new File("G:/index.html").toURI().toString();
FileOutputStream out = new FileOutputStream(new File("G:"+ File.separator+"cssbox.png"));
Thread.sleep(10000);
render.renderURL(url, out, ImageRenderer.Type.PNG);
System.out.println("OK");
}

---------------------
作者:青春微凉love
来源:CSDN
原文:https://blog.csdn.net/qq_36029699/article/details/86507825
版权声明:本文为博主原创文章,转载请附上博文链接!

原文地址:https://www.cnblogs.com/lixiaoran/p/10594023.html