GrabzIt
Tools to Capture and Convert the Web

Capture Website Screenshots or Convert HTML to ImagesJava API

Create perfect image screenshots of websites or convert HTML straight to images by using the following features of GrabzIt's Java API. However before you start remember that after calling the URLToImage, HTMLToImage or FileToImage methods the Save or SaveTo method must be called to take the screenshot.

Basic Options

Just one parameter is required in order to take a screenshot of a web page or convert HTML into a image as shown in the following example.

grabzIt.URLToImage("http://www.google.com");
grabzIt.HTMLToImage("<html><body><h1>Hello World!</h1></body></html>");
grabzIt.FileToImage("example.html");

Image Screenshot Formats

Warning At least a Entry Package is required to use image formats other than JPG. Try it for free with a 7 day free trial. Then from $5.99 a month, unless cancelled.Start 7 Day Free Trial

GrabzIt's Java API can take image screenshots in several formats, including JPG, PNG, BMP (8 bit, 16 bit, 24 bit or 32 bit) and TIFF. The default format for image screenshots is JPG. However the quality of a JPG image may not be good enough for some applications in these circumstances the PNG format is recommended for image screenshots as it gives a good balance between quality and file size. The below example shows an image screenshot being taken using the PNG format.

ImageOptions options = new ImageOptions();
options.setFormat(ImageFormat.PNG);

grabzIt.URLToImage("http://www.google.com", options);
ImageOptions options = new ImageOptions();
options.setFormat(ImageFormat.PNG);

grabzIt.HTMLToImage("<html><body><h1>Hello World!</h1></body></html>", options);
ImageOptions options = new ImageOptions();
options.setFormat(ImageFormat.PNG);

grabzIt.FileToImage("example.html", options);

Browser Size

The browser size refers to the size of the browser window that will be used when capturing the screenshot in most cases this does not need to be set as the default browser size will be sufficent for all most all tasks. To set the browser size just pass a value to the setBrowserWidth and setBrowserHeight methods of the ImageOptions class.

Avoiding a Distorted Screenshot

To avoid a distorted image when specifying the image size using the setOutputWidth and setOutputHeight methods ensure that the same ratio is kept between each dimension. For instance if you want a screenshot with a width of 256, which is a quarter of the default browser width of 1024, then the height must be a quarter of the default browser height of 800. So the final dimensions would be 256 × 200. Use this tool to automatically calculate the correct dimensions.

Custom Identifier

You can pass a custom identifier to the image methods as shown below, this value is then returned to your GrabzIt Java handler. For instance this custom identifier could be a database identifier, allowing a screenshot to be associated with a particular database record.

ImageOptions options = new ImageOptions();
options.setCustomId(123456");

grabzIt.URLToImage("http://www.google.com", options);
ImageOptions options = new ImageOptions();
options.setCustomId("123456");

grabzIt.HTMLToImage("<html><body><h1>Hello World!</h1></body></html>", options);
ImageOptions options = new ImageOptions();
options.setCustomId("123456");

grabzIt.FileToImage("example.html", options);

Full Length Screenshot

Warning At least a Professional Package is required to use full length screenshots. Try it for free with a 7 day free trial. Then from $14.99 a month, unless cancelled.Start 7 Day Free Trial

GrabzIt allows you to take a full length screenshot of an entire web page to do this you need to pass a -1 to the setBrowserHeight method.

ImageOptions options = new ImageOptions();
options.setBrowserHeight(-1);

grabzIt.URLToImage("http://www.google.com", options);
ImageOptions options = new ImageOptions();
options.setBrowserHeight(-1);

grabzIt.HTMLToImage("<html><body><h1>Hello World!</h1></body></html>", options);
ImageOptions options = new ImageOptions();
options.setBrowserHeight(-1);

grabzIt.FileToImage("example.html", options);

You can also return thumbnails that are not cropped, but beware this can create large images. To do this pass a -1 to the setHeight and/or setWidth methods. Any dimension that is passed a -1 will not be cropped.

ImageOptions options = new ImageOptions();
options.setWidth(-1);
options.setHeight(-1);

grabzIt.URLToImage("http://www.google.com", options);
ImageOptions options = new ImageOptions();
options.setWidth(-1);
options.setHeight(-1);

grabzIt.HTMLToImage("<html><body><h1>Hello World!</h1></body></html>", options);
ImageOptions options = new ImageOptions();
options.setWidth(-1);
options.setHeight(-1);

grabzIt.FileToImage("example.html", options);
Note there is no full length browser width!

Using these special values means that you can create a screenshot that is a full scale version of the entire web page if you wish!

Take a Screenshot of a Page Element

Warning At least a Entry Package is required to use HTML element capture. Try it for free with a 7 day free trial. Then from $5.99 a month, unless cancelled.Start 7 Day Free Trial

GrabzIt allows you to take a screenshot of any HTML element as long as it has a id or class attribute, such as a div or span tag, and capture all its content. To do this the id or class of the HTML element you want to screenshot must be specified as a CSS Selector.

...
<div id="features">
	<img src="http://www.example.com/football.jpg"/><h3>Local Team Loses</h3>
</div>
...

In the below example the div with the id "features" is captured and output as a 250 x 250px JPEG image.

// The 250 parameters indicates that image should be sized to 250 x 250 px
ImageOptions options = new ImageOptions();
options.setWidth(250);
options.setHeight(250);
options.setFormat(ImageFormat.JPG);
options.setTargetElement("#features");

grabzIt.URLToImage("http://www.bbc.co.uk/news", options);

The next example again captures the "features" div but this time outputs a JPEG image that is exactly the same size of the div.

// The -1 indicates that image should not be cropped
ImageOptions options = new ImageOptions();
options.setWidth(-1);
options.setHeight(-1);
options.setBrowserHeight(-1);
options.setFormat(ImageFormat.JPG);
options.setTargetElement("#features");

grabzIt.URLToImage("http://www.bbc.co.uk/news", options);