I think chromedriver (selenium-webdriver / chrome) can do it (although it's 
pretty hacky).

You have to
- List the current window handles
- call window.print
- re-list the current window handles, remove the ones that were there 
before (to get the handle for the print window)
- tell selenium to switch to the print window
- use javascript to switch to pdf output (change... -> save as pdf)
- use javascript to click the 'print' button
- hit save (not 100% sure this part works nicely as it opens a system 
dialog but at least one person has reported it working.)

https://code.google.com/p/chromedriver/issues/detail?id=19 is the issue to 
star if you want to know when this gets better support.

Finally, if you're more comfortable with C++ than I am (I'm not), the 
chromium source is really very readable. 
It shouldn't be hard to hook up the built-in pdf generation to the 
chromedriver bindings.


On Wednesday, November 7, 2012 5:14:58 PM UTC+11, Tim McEwan wrote:
>
>  Hi all, 
>
> I want to automate the creation of around 100 PDFs with user data and 
> graphics generated by JS (charts mostly, but maybe some Raphael).  Each PDF 
> is an energy bill.  The whole environment can be controlled, so it doesn't 
> need to be client-side cross-platform or anything.  However, we'd like to 
> be able to package it up and have others use it, so the simpler the better.
>
> I've looked at Prawn, but I'd rather not have to draw everything from 
> first principles.  It seems wkhtmltopdf is a better bet so I tested it on 
> highcharts.com.  It does a good job <http://cl.ly/2l1c3C083u3N>, but not 
> as good as straight Safari <http://cl.ly/2Q0F0J0C022a>.  So I thought 
> perhaps I'd automate a browser instead, but that may not be so 
> simple<http://stackoverflow.com/questions/11537103/how-to-handle-print-dialog-in-selenium>
> .
>
> Has anyone got any tips on the best way to go?
>
> Thanks,
> Tim
>
>
>  

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
or Rails Oceania" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/rails-oceania/-/bP6oZnJAlgQJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rails-oceania?hl=en.

Reply via email to