使用net.sf.cssbox实现网页截图

需要引用包,在pom.xml中添加引用:

1         <dependency>
2             <groupId>net.sf.cssboxgroupId>
3             <artifactId>cssboxartifactId>
4             <version>4.12version>
5         dependency>

实现代码:

package com.dx.project01;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import org.fit.cssbox.demo.ImageRenderer;
import org.xml.sax.SAXException;

/**
 * Hello world!
 */
public class App {
    public static void main(String[] args) throws IOException, SAXException {
        ImageRenderer render = new ImageRenderer();
        System.out.println("start...");
        String url = "https://mvnrepository.com/artifact/net.sf.cssbox/cssbox/4.12";
        FileOutputStream out = new FileOutputStream(new File("D:" + File.separator + "html.png"));
        render.renderURL(url, out, ImageRenderer.Type.PNG);
        out.close();
        System.out.println("OK");
    }
}

示例:实现截图地址https://mvnrepository.com/artifact/net.sf.cssbox/cssbox/4.12

截图效果:

使用net.sf.cssbox实现网页截图_第1张图片

 

你可能感兴趣的:(使用net.sf.cssbox实现网页截图)