dfrankow
dfrankow

Reputation: 21447

Print a file from Watir

I'm looking at Watir-Webdriver to manipulate a browser. In particular, I'd like to open a local file and print it to a PDF file.

Yes, wkhtmltopdf would be a good thing, but it's not working for me on debian squeeze, for reasons that are difficult to ascertain. The page contains Javascript, which rules out many html-to-pdf options. wkhtmltopdf works on OS X, same version (0.9.9), so I know it's not a problem with how I'm using it (PDFKit and Ruby). I'd just like to sidestep these issues and try a different way. Opening up chromium on debian shows a perfectly rendered page.

How does one "print" from Watir?

Edit: After more reading, I think there is no way to do this.

Upvotes: 0

Views: 1002

Answers (2)

Chuck van der Linden
Chuck van der Linden

Reputation: 6660

You'll need to use something that lets you do automation at the OS level. such as Autoit or maybe RAutomation. not sure what exists to do this on *nix operating systems.

Watir only drives the browser in terms of what is inside the browser window, it has very limited capability to work the menus of the browser itself.

Upvotes: 0

Alister Scott
Alister Scott

Reputation: 3685

You could take a png sreenshot, then use the prawn gem to convert the png screenshot to a pdf:

require 'prawn'
require 'watir-webdriver'

b = Watir::Browser.start 'watirwebdriver.com'
b.driver.save_screenshot 'screenshot.png'
Prawn::Document.generate 'screenshot.pdf' do
  image 'screenshot.png', :scale => 0.5
end
b.close 

Upvotes: 2

Related Questions