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.

有帮助吗?

解决方案

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 

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top