Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print a web page from within R

Tags:

r

I can open a web page from within R:

shell.exec("http://stackoverflow.com/")

But how can I then print this webpage, directly from within R, as an xps or pdf file?

like image 363
adam.888 Avatar asked Aug 29 '14 09:08

adam.888


2 Answers

You can invoke a command line tool called wkhtmltopdf, which is both open source and cross-platform:

shell("C:\\wkhtmltopdf\\bin\\wkhtmltopdf http://stackoverflow.com so.pdf")

Do not forget to escape backslashes!

like image 131
tonytonov Avatar answered Oct 04 '22 21:10

tonytonov


I realise this is an old question, but you can use the webshot package to do this.

# install.packages("webshot")

library(webshot)

webshot("https://stackoverflow.com/", "stackoverflow.pdf")
like image 28
conrad-mac Avatar answered Oct 04 '22 21:10

conrad-mac