尝试在 R 中抓取 PDF,我的代码只会抓取 9 页中的 6 页,我不确定为什么,我的代码中是否遗漏了什么?

Trying to scrape a PDF in R, my code will only scrape 6 out of 9 pages and i'm not sure why, am I missing something in my code?

我试图在 R 中抓取几个 PDF,PDF1 有 9 页,PDF2 有 12 页。当我 运行 下面的代码会抓取两个 PDF,但只抓取第 6 页,之后什么也没有。是否有一个原因?我的代码中缺少什么?

library(tm)
read <- readPDF(engine = "xpdf", control = list(text = "-layout")) 
document <- Corpus(URISource("C:\Users\Goku\Documents\Python Scripts\PDF Scraping\123.pdf"), readerControl = list(reader = read))
doc <- content(document[[1]])
head(doc)

您可以在以下位置找到 pdf:https://www.scribd.com/document/396797318/123

我无法重现您的问题。使用你的文件,我得到了 12 页的两种方式阅读文本。检查它们是否相同也会产生 true。

tm 与 readerpdftools:

library(tm)

read <- readPDF(engine = "pdftools", control = list(text = "-layout")) 
document <- Corpus(URISource("396797318-123.pdf"), readerControl = list(reader = read))

直接使用 pdftools:

library(pdftools)

text <- pdf_text("396797318-123.pdf")

检查它们是否相同:

tm_text <- as.vector(sapply(document, as.character))
identical(text, tm_text)
[1] TRUE

str(document)
List of 1
 $ 396797318-123.pdf:List of 2
  ..$ content: chr [1:12] "            Training and Development Policy\r\n                                                     Contents\r\"| __truncated__ "1.2 As a guiding principle, all staff must be offered appropriate and relevant\r\n     development opportunitie"| __truncated__ "   • Short Term Externally Provided Training (e.g. one or two day external\r\n     courses)\r\n   • Longer Term"| __truncated__ "     are at no cost) together with periodic training bulletins informing employees of\r\n     impending courses"| __truncated__ ...
  ..$ meta   :List of 7
  .. ..$ author       : chr "leanne.cutts"
  .. ..$ datetimestamp: POSIXct[1:1], format: "2014-02-28 17:57:34"
  .. ..$ description  : chr ""
  .. ..$ heading      : chr "Training and Development Policy"
  .. ..$ id           : chr "396797318-123.pdf"
  .. ..$ language     : chr "en"
  .. ..$ origin       : chr "PDFCreator Version 1.4.3"
  .. ..- attr(*, "class")= chr "TextDocumentMeta"
  ..- attr(*, "class")= chr [1:2] "PlainTextDocument" "TextDocument"
 - attr(*, "class")= chr [1:2] "VCorpus" "Corpus"