为了帮助您入门,这里是一个readPDF
用于读取 PDF 文件的完整命令的示例。readPDF
当我尝试直接从您提供的链接中检索 PDF 文件时抛出错误,因此我首先将 PDF 文件下载到我的工作目录。
library(tm)
# File name
filename = "ea0607.pdf"
# Read the PDF file
doc <- readPDF(control = list(text = "-layout"))(elem = list(uri = filename),
language = "en",
id = "id1")
上面的代码将 PDF 文件转换为文本并将结果存储在doc
. doc
实际上是一个列表,从下面的代码可以看出:
str(doc)
List of 2
$ content: chr [1:23551] " STATE UNIVERSITY SYSTEM OF FLORIDA" "" "EXPENDITURE ANALYSIS" " 2006-2007" ...
$ meta :List of 7
..$ author : chr "greg.jacques"
..$ datetimestamp: POSIXlt[1:1], format: "2007-12-10 11:33:48"
..$ description : NULL
..$ heading : chr " PGM=EASUSI-V01 STATE UNIVERSITY SYSTEM "| __truncated__
..$ id : chr "ea0607.pdf"
..$ language : chr "en"
..$ origin : chr "Acrobat PDFMaker 8.1 for Word"
..- attr(*, "class")= chr "TextDocumentMeta"
- attr(*, "class")= chr [1:2] "PlainTextDocument" "TextDocument"
PDF 文件的文本存储在 中doc$content
,同时doc$meta
包含有关 PDF 文件的各种元数据。每行doc$content
是 PDF 文件中的一行。这是 PDF 文件的第 300 到 310 行:
doc$content[300:310]
[1] ""
[2] "and General (E&G) budget entity. The Expenditure Analysis continues to reflect special units separately and the"
[3] ""
[4] "traditional program components and related activities have been further defined to support the funding formula. The"
[5] ""
[6] "Expenditure Analysis format was revised in 1995-96 to include all activities in the funding formula as well as college"
[7] ""
[8] "detail by activity for the UF Health Science Center, the USF Health Science Center and the FSU Medical School. A"
[9] ""
[10] "definition of each follows:"
[11] ""
希望这将帮助您入门。