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"));


}
}

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.

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();
doc.setTokenThreshold(Integer.MAX_VALUE);
doc.setAsynchronousLoadPriority(-1);
return doc;
}
}

public static BufferedImage create(String src, int width, int height)
{
BufferedImage image = null;
JEditorPane pane = new JEditorPane();
Kit kit = new Kit();
pane.setEditorKit(kit);
pane.setEditable(false);
pane.setMargin(new Insets(0,0,0,0));
try {
pane.setPage(src);
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);
g.dispose();
} catch (Exception e) {
System.out.println(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.

Thanx NormR1 for Reply so instead of JEditorPane what should i use.

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.

Did you try flying saucer?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.