Tools to Capture and Convert the Web

Take Website Screenshots with Ruby

Ruby API
The diagnostics panel can help you debug your code!

GrabzIt's screenshot API is very flexible and can be called from any type of Ruby application. The best way to put website screenshots or HTML to image functionality and more into your Ruby app is by following these steps:

  1. Get your free Application Key and Secret.
  2. Download the free Ruby Library and try out the Demo Application.
  3. Find out the basics about how GrabzIt's API works by reading the below overview.

Ruby API Overview

First create an instance of the Client class, passing your application key and application secret from your GrabzIt account to the constructor to start using GrabzIt's API .

require 'grabzit'

grabzItClient = GrabzIt::Client.new("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
grabzItClient.url_to_image("https://www.tesla.com")	
# Or to take a PDF screenshot
grabzItClient.url_to_pdf("https://www.tesla.com")
# Or to convert online videos into animated GIF's
grabzItClient.url_to_animation("http://www.example.com/video.avi")
# Or to capture table(s)
grabzItClient.url_to_table("https://www.tesla.com")
# To convert HTML into a image
grabzItClient.html_to_image("<html><body><h1>Hello World!</h1></body></html>")	
# Or convert HTML into a PDF document
grabzItClient.html_to_pdf("<html><body><h1>Hello World!</h1></body></html>")
# Or convert HTML into a CSV, XLSX or JSON document
grabzItClient.html_to_table("<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
grabzItClient.file_to_image("example.html")	
# Or convert HTML file into a PDF document
grabzItClient.file_to_pdf("example.html")
# Or convert HTML file into a CSV, XLSX or JSON document
grabzItClient.file_to_table("tables.html")

Finally use one of the following save methods to complete the capture. The Save method requires the URL of a handler, which will process the callback from GrabzIt to save the resulting screenshot.

grabzItClient.save("http://www.example.com/handler/index") 	
Always use the save_to method on localhost

Another option is to use the synchonous save_to 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.

Once the capture is created it is saved to the file path provided.

filepath = "images/result.jpg"
grabzItClient.save_to(filepath) 	

More Options

There are many special features that can be used when taking screenshots of webpages or converting HTML. 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 please read the Client documentation.