Manage Learn to apply best practices and optimize your operations.

Converting Web pages to images using Java

Learn how you can use Java code to convert Web pages to images with the click of a button.

I was recently asked to come up with some Java code that would convert Web pages into images.

My objective was to have the Web page become an image upon the clicking of a button or when certain events happened. Below is the Java code I came up with, I hope it works as well for you as it did for me.

//Call the Web page and convert to Image
BufferedImage ire;
ire = WebImage.create("<web page URL>", 800, 600);
//You can convert the BufferedImage to 
any format that you wish, jpg I thought was the best format
ImageIO.write(ire, "jpg", new File

//Class that Converts the web page to Image
import java.awt.*;
import java.awt.image.*;
import javax.swing.*;
import javax.swing.text.*;
import javax.swing.text.html.*;

public abstract class WebImage 
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();
(g, pane, c, 0, 0, width, height);
} catch (Exception e) {
return image;


Wouldn't it just be easier to hit the PrintScreen button or Alt+PrintScreen to bring up only the active window?
—Leonard V.

Do you have comments on this tip? Let us know.

Related information from

This tip was submitted to the tip library by member Michael Marcavage. Please let others know how useful it is via the rating scale below. Do you have a useful Lotus Notes, Domino, Workplace or WebSphere tip or code snippet to share? Submit it to our monthly tip contest and you could win a prize.

Dig Deeper on Java for Lotus Notes Domino



  • Favorite iSeries cheat sheets

    Here you'll find a collection of valuable cheat sheets gathered from across the iSeries/ community. These cheat ...

  • HTML cheat sheet

    This is a really cool cheat sheet if you're looking to learn more about HTML. You'll find just about everything you every wanted ...

  • Carol Woodbury: Security

    Carol Woodbury