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:
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 DOCX, image, PDF, animation or table options 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")
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)
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. There are also more advanced examples available.