【问题标题】:Problems with Downloading pdf file using R使用 R 下载 pdf 文件的问题
【发布时间】:2012-03-06 00:27:27
【问题描述】:

我想从互联网上下载一个 pdf 文件并将其保存在本地高清中。下载后,pdf输出文件有很多空白页。我能做些什么来解决它?

例子:

require(XML)
url <- ('http://cran.r-project.org/doc/manuals/R-intro.pdf')
download.file(url, 'introductionToR.pdf')

提前致谢。

【问题讨论】:

  • 我复制并粘贴了您的代码,得到了应有的 109 页文档。您的 PDF 查看器可能有问题?
  • 对我来说很好。 (R 2.14.1,Linux - 你能发布sessionInfo() 的结果吗?它似乎确实可能是查看器或其他一些操作系统问题,因为这是非常基本的功能......)顺便说一句,你不为此需要 XML 包 -- download.file 是基础 R 的一部分。
  • 附言。我猜你在 Windows 上:?download.file 说:“为下载二进制文件而编写的代码必须使用 'mode = "wb"',但文本传输引起的问题只会在 Windows 上看到。”跨度>
  • 我遇到了和 OP 一样的问题。下载的 PDF 将被损坏。该死的'wb'参数解决了问题

标签: r pdf


【解决方案1】:

像这样尝试使用 wb-mode:

download.file(url, 'introductionToR.pdf', mode="wb")

对我来说就是这样。

【讨论】:

  • 这个答案为我节省了大量工作! (在 win 操作系统上)
  • 添加解释,mode="wb" 告诉函数将文件视为二进制文件而不是文本。
【解决方案2】:

您可以使用 tabulizer 包下载 pdf 并将表格导出为 data.frame

https://ropensci.org/tutorials/tabulizer_tutorial.html

install.packages("devtools")
# on 64-bit Windows
ghit::install_github(c("ropenscilabs/tabulizerjars", "ropenscilabs/tabulizer"), INSTALL_opts = "--no-multiarch")
# elsewhere
ghit::install_github(c("ropenscilabs/tabulizerjars", "ropenscilabs/tabulizer"))

library(tabulizer)

f2 <- "https://github.com/leeper/tabulizer/raw/master/inst/examples/data.pdf"
extract_tables(f2, pages = 1, method = "data.frame")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多