I have created a screen capture of the current screen ,but i want to capture the entire html page as image can any body help me. Here is the code of screen capture..

import java.io.*;
import java.awt.*;
import java.awt.image.*;
import javax.imageio.*;

class A
public static void main(String[] ar) throws Exception
Robot r=new Robot();
Dimension d=Toolkit.getDefaultToolkit().getScreenSize();
Rectangle rct=new Rectangle(0,0,d.width,d.height);
BufferedImage bimg=r.createScreenCapture(rct);
ImageIO.write(bimg,"jpeg",new File("D:/screen_capture.jpg"));

4 Years
Discussion Span
Last Post by JamesCherrill

i want to capture the entire html page as image

I assume that you are talking about an html page being displayed in a browser. And the html page is too long to view on the screen requiring that the browser scroll forward to the next viewing. You want to screen print each viewing and "stitch" together the several images into one image removing any overlapping?


Thanx for the reply NormR1.you assumed exact what i want to make,so can you please help me related to this.


I have no idea how to write that kind of code. Comparing two images to find where they can be "stitched" together could be a process of reading "rows" of pixels from the top of the following image and then from the bottom of the preceding image and then backing up until the rows match. There could be some false matches so the code could be complicated.

Edited by NormR1


Here i have made a code to save webpage as image but i does'nt works properly i.e it fails to capture those web pages which have more of multimedia content e.g youtube page google images page and photoshop website etc.


here is the code

package htmltoimage;
import java.awt.*;
import java.awt.image.*;
import javax.swing.*;
import javax.swing.text.*;
import javax.swing.text.html.*;
import java.awt.*;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;

public abstract class HtmlToImage 
static class Kit extends HTMLEditorKit 
public Document createDefaultDocument() {
HTMLDocument doc = (HTMLDocument) super.createDefaultDocument();
return doc;

public static BufferedImage create(String src, int width, int height)
BufferedImage image = null;
JEditorPane pane = new JEditorPane();
Kit kit = new Kit();
pane.setMargin(new Insets(0,0,0,0));
try {
image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics g = image.createGraphics();
Container c = new Container();
SwingUtilities.paintComponent(g, pane, c, 0, 0, width, height);
} catch (Exception e) {
return image;

public static void main(String[] args) throws IOException 
BufferedImage ire;
ire = HtmlToImage.create("http://flyingsaucerproject.github.com/flyingsaucer/r8/guide/users-guide-R8.html#xil_29", 1024, 5000);
ImageIO.write(ire, "jpg", new File("c:\\My PDF\\tt.jpg"));

fails to capture those web pages which have more of multimedia content

I don't think the JEditorPane class does everything a browser does with html, javascript, etc.


I don't know of any better class in the java SE classses if you are looking for code that displays an html page the same as a full browser does.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.