Installation
Sign up and obtain your username and API key — https://pdfcrowd.com/user/sign_in/
$ gem install pdfcrowd
Or download pdfcrowd-2.3.0.gem and run
Get the API key from your account page
Code:
require 'rubygems'
require 'pdfcrowd'
require 'watir-webdriver'
# create an API client instance
username="YOUR USERNAME"
apikey="YOUR API KEY"
client = Pdfcrowd::Client.new(username, apikey)
# convert an HTML string and save the result to a file
browser=Watir::Browser.new :ff
browser.goto("https://raveendran.wordpress.com")
html=browser.html
File.open('html.pdf', 'wb') {|f| client.convertHtml(html, f)}
# retrieve the number of tokens in your account
ntokens = client.numTokens()
Output:
After ran the script, you will get the html.pdf file in the same directory.