In java, HTML is converted into an image file. The idea is that the webpage is displayed on the AWT or Swing Panel and the Panel is output as an image file. Java APIs provide relevant results, but the results are not very good, so there are some libraries. java Core API [java] public class HtmlToImage {protected static void generateOutput () throws Exception {// load the webpage into the editor // JEditorPane ed = new JEditorPane (new URL ("http://www.google.com ")); JEditorPane ed = new JEditorPane (new URL ("http://www.hefeipet.com/client/chongwuzhishi/shenghuozatan/2012/0220/95.html"); ed. setSize (, 20 0); // create a new image BufferedImage image = new BufferedImage (ed. getWidth (), ed. getHeight (), BufferedImage. TYPE_INT_ARGB); // paint the editor onto the image SwingUtilities. paintComponent (image. createGraphics (), ed, new JPanel (), 0, 0, image. getWidth (), image. getHeight (); // save the image to file ImageIO. write (RenderedImage) image, "png", new File ("html.png");} public static void main (String [] Args) {try {generateOutput ();} catch (Exception e) {e. printStackTrace () ;}} java-html2image open source, very concise to use. Both API Doc and source code are available. [Java] import gui.ava.html. image. generator. htmlImageGenerator; public class Html2ImageTest {public static void main (String [] args) {HtmlImageGenerator imageGenerator = new HtmlImageGenerator (); // imageGenerator //. loadHtml ("<B> Hello World! </B> Please goto <a title = \ "Goto Google \" href = \ "http://www.google.com \"> Google </a>. "); // imageGenerator. loadUrl ("http: // mtkplmap2: 7001/esdm_web"); imageGenerator. loadUrl ("http://www.hefeipet.com/client/chongwuzhishi/shenghuozatan/2012/0220/95.html"); imageGenerator. saveAsImage ("hello-world.png"); imageGenerator. saveAsHtmlWithMap ("hello-world.html", "hello-world.png") ;}} Cobra free, open source [java] public class CobraTest {public static void main (String [] args) throws Exception {JFrame window = new JFrame (); HtmlPanel panel = new HtmlPanel (); window. getContentPane (). add (panel); window. setSize (600,400); window. setVisible (true); new SimpleHtmlRendererContext (panel, new SimpleUserAgentContext ()). navigate ("http://www.hefeipet.com/client/chongwuzhishi/shenghuozatan/2012/0220/95.html"); BufferedImage image = new BufferedImage (panel. getWidth (), panel. getHeight (), BufferedImage. TYPE_INT_ARGB); // paint the editor onto the image SwingUtilities. paintComponent (image. createGraphics (), panel, new JPanel (), 0, 0, image. getWidth (), image. getHeight (); // save the image to file ImageIO. write (RenderedImage) image, "png", new File ("html.png "));}}