R脚本-PDF错误:十六进制字符串中的非法字符;当我搜索关键字时

R脚本-PDF错误:十六进制字符串中的非法字符;当我搜索关键字时,r,pdf,text-mining,R,Pdf,Text Mining,我正在尝试计算多个pdf文件中的关键字数 library(tm) library(pdftools) files <- list.files(pattern = "pdf$") Rpdf <- readPDF(control = list(text = "-layout")) corp <- Corpus(URISource(files), readerControl = list(reader = Rpdf)) words <- c("example", "keyw

我正在尝试计算多个pdf文件中的关键字数

library(tm)
library(pdftools)

files <- list.files(pattern = "pdf$")
Rpdf <- readPDF(control = list(text = "-layout"))
corp <- Corpus(URISource(files), readerControl = list(reader = Rpdf))

words <- c("example", "keyword", "test")
dt <- DocumentTermMatrix(corp, control=list(dictionary=words))
library(tm)
图书馆(pdftools)

文件我猜您的PDF格式是二进制文件,因此应该作为二进制文件下载/读取。我在下载pdf文件时遇到了类似的问题,
download.file
。下载完pdf后,我无法使用
pdftools
从pdf中挖掘信息。我发现我的pdf文件中有二进制文件,有坏的bc文件,我没有以正确的格式下载它们(尝试使用任何pdf阅读器,打开pdf时应该说它坏了)。使用Windows作为操作系统,我将
mode=“wb”
添加到
download.file
中,确保以正确的格式存储它们。然后,我可以在它上面运行
pdftools
中的函数,而不会显示错误消息。希望这能有所帮助。从这个问题中得到了想法:

与您的错误消息相同:

pdf_toc(example_path)
PDF error (1151926): Illegal character <3a> in hex string
PDF error (1151929): Illegal character <73> in hex string
[...omitted for brevity...]
PDF error (1152006): Illegal character <22> in hex string
PDF error: Couldn't find trailer dictionary
PDF error: Couldn't read xref table
Error in poppler_pdf_toc(loadfile(pdf), opw, upw) : PDF parsing failure.
pdf\u目录(示例路径)
PDF错误(1151926):十六进制字符串中的非法字符
PDF错误(1151929):十六进制字符串中的非法字符
[…为简洁起见省略…]
PDF错误(1152006):十六进制字符串中的非法字符
PDF错误:找不到拖车字典
PDF错误:无法读取外部参照表
poppler\u pdf\u toc(加载文件(pdf)、opw、upw)中出错:pdf解析失败。

我无法重现您的错误。您必须指向生成此错误的示例pdf。另外,请将
警告()的结果添加到您的问题中。
库(pdftools)
。如果您尝试使用它,会发生什么情况?库(pdftools)工作正常,完全没有错误。@DanielMeyer-您找到解决方案了吗?在一大组文件
pdf错误(21):非法字符“{”
”中的一个特定pdf文件上,我也遇到了类似的错误,这将中止我的所有处理,直到那时。您是如何设法绕过此错误的?
pdf_toc(example_path)
PDF error (1151926): Illegal character <3a> in hex string
PDF error (1151929): Illegal character <73> in hex string
[...omitted for brevity...]
PDF error (1152006): Illegal character <22> in hex string
PDF error: Couldn't find trailer dictionary
PDF error: Couldn't read xref table
Error in poppler_pdf_toc(loadfile(pdf), opw, upw) : PDF parsing failure.