There are several ways that the GrabzIt API can be used to take screenshots and more in Java. To get started with the API follow these steps:
The first stage on starting to use the API in your Java App is to create an instance of the GrabzItClient class, passing your application key and application secret from your GrabzIt account to the constructor.
//Create the GrabzItClient class //Replace "APPLICATION KEY", "APPLICATION SECRET" with the values from your account! GrabzItClient grabzIt = new GrabzItClient("Sign in to view your Application Key", "Sign in to view your Application Secret");
Then use one of the image, PDF, animation or table methods to capture a URL or convert HTML.
// To take a image screenshot grabzIt.URLToImage("https://www.tesla.com"); // Or to take a PDF screenshot grabzIt.URLToPDF("https://www.tesla.com"); // Or to convert online videos into animated GIF's grabzIt.URLToAnimation("http://www.example.com/video.avi"); // Or to capture table(s) grabzIt.URLToTable("https://www.tesla.com");
// To convert HTML into a image grabzIt.HTMLToImage("<html><body><h1>Hello World!</h1></body></html>"); // Or convert HTML into a PDF document grabzIt.HTMLToPDF("<html><body><h1>Hello World!</h1></body></html>"); // Or convert HTML into a CSV, XLSX or JSON document grabzIt.HTMLToTable("<html><body><table><tr><th>Name</th><th>Age</th></tr> <tr><td>Tom</td><td>23</td></tr><tr><td>Nicola</td><td>26</td></tr> </table></body></html>");
// To convert HTML file into a image grabzIt.FileToImage("example.html"); // Or convert HTML file into a PDF document grabzIt.FileToPDF("example.html"); // Or convert HTML file into a CSV, XLSX or JSON document grabzIt.FileToTable("tables.html");
Next the result must be saved by using use one of the following two save methods. With the Save method the URL of a handler needs to be specified, which will process the callback from GrabzIt and save the resulting screenshot. As this method requires a callback handler it is usually only possible to use this approach in a web application.
grabzIt.Save("http://www.example.com/handler");
Alternatively use the synchonous SaveTo method, which will force your application to wait while the screenshot is created so it should only be used were the Save method cannot be used, such as in a desktop application.
Once the screenshot is created it is saved to the file path provided.
String filepath = "images/result.jpg"; grabzIt.SaveTo(filepath);
All of our online services such as creating web captures, animated GIF's or converting HTML have many customizable options including; configuring the browser height, browser width, screenshot height, screenshot width, the delay before a screenshot is taken and the image format of the screenshot. For all these options and more information on creating PDF's, animated GIF's and CSV's from web content please see the Client documentation.