更新:如果你安装了 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)