将文件转换(打印)为PDF - 使用R?(在windows中)

Tal*_*ili 7 html pdf r

我希望使用R将HTML文件转换为PDF文件.

是否有可以执行此转换的命令或工具/命令的组合?

Ric*_*ton 5

更新:如果你安装了 Pandoc,你可以使用类似的东西

html_to_pdf <- function(html_file, pdf_file) {
  cmd <- sprintf("pandoc %s -t latex -o %s", html_file, pdf_file)
  system(cmd)
}
Run Code Online (Sandbox Code Playgroud)

有一些 Web 服务可以将 HTML 转换为 PDF 并具有 REST API,因此您可以使用RCurl. 快速的互联网搜索提供pdfcrowd.com。它们允许您上传文档以及转换 URL,但这是一项付费服务​​。

下一个热门是joliprint,它是免费的。尝试这个:

library(RCurl)
url_to_convert <- curlEscape("http://lifehacker.com/5706937/dont-make-important-decisions-until-your-decision-time") #or wherever

the_pdf <- getForm(
  "http://eu.joliprint.com/api/rest/url/print", 
  url = url_to_convert
)
Run Code Online (Sandbox Code Playgroud)