10

I wish to convert an HTML file into a PDF file, using R.

Is there a command, or a combination of tools/commands, that can perform this conversion?

Tal Galili
  • 24,605
  • 44
  • 129
  • 187
  • Not really an R question, since there's no way R can do this. You'd have to call an external utility, which is the easy step in doing this from R. The hard step is HTML to PDF conversion - by 'HTML file' do you mean the _rendered_ version of it or the plain HTML text? To render HTML you pretty much need a web browser to handle the images, stylesheets, javascript possibly. – Spacedman Sep 20 '11 at 08:22
  • Hi spacedman - I mean the plain HTML text. If I understand you correctly, I'd need to have R "run" the print command from my browser. Is that even possible? – Tal Galili Sep 20 '11 at 08:56
  • 1
    So you want an HTML pretty-printer? Highlighting tags, colouring text, that kind of thing? – Spacedman Sep 20 '11 at 09:29
  • Yes. I want to create an HTML report in R, and then automatically print it to PDF if I'd need to send it as such a file... – Tal Galili Sep 20 '11 at 09:36
  • Still not clear... What's an HTML report? You want to make a file with things like
  • The error was 2.334
  • etc etc and then make a PDF with the formatted output (ie lists with bullets, headings sized correctly and so on)? – Spacedman Sep 20 '11 at 13:12
  • Thanks Spacedman - indeed - that is what I am after – Tal Galili Sep 20 '11 at 14:53
  • How about a more generic markup language such as asciidoc (package `ascii`) that can be processed by `R` to obtain both pdf and html output? – baptiste Sep 20 '11 at 20:50
  • It sound like what your asking is addressed in the thread below. I assume the only reason you'd wand to convert is if you have an r markdown file. http://stackoverflow.com/questions/11025123/how-to-convert-r-markdown-to-pdf –  Oct 11 '13 at 00:00
  • I'm doing some web-scraping with R and would like to convert selected HTML files to pdf for storage and later reviewing. Anybody know updates to this since 2013? – J. Win. May 17 '18 at 18:19