R 尝试从具有不同表格格式的长PDF中提取

R 尝试从具有不同表格格式的长PDF中提取,r,pdf,data-extraction,pdf-scraping,tabulizer,R,Pdf,Data Extraction,Pdf Scraping,Tabulizer,我正试图从276页的PDF中抓取以下内容: 文档不仅很长,而且还有不同格式的表格。我尝试在tabulizer库中使用extract_tables()函数。这成功地从文档第143页开始刮取数据表,但不适用于第18-75页的表。这些书页可以拆开吗?如果是,为什么 我收到的错误消息显示“列多于列名”和“行重复。不允许使用名称” child\u支持\u scrap,因为pdf文件中的文本不是以纯文本格式存储的。通常很难从pdf文件中提取文本。以下方法提供了从pdf中提取表的替代方法。它需要pdftool

我正试图从276页的PDF中抓取以下内容:

文档不仅很长,而且还有不同格式的表格。我尝试在tabulizer库中使用extract_tables()函数。这成功地从文档第143页开始刮取数据表,但不适用于第18-75页的表。这些书页可以拆开吗?如果是,为什么

我收到的错误消息显示“列多于列名”和“行重复。不允许使用名称”


child\u支持\u scrap,因为pdf文件中的文本不是以纯文本格式存储的。通常很难从pdf文件中提取文本。以下方法提供了从pdf中提取表的替代方法。它需要
pdftools
plyr

# Download the pdf file as a variable in R
pdf_text <- pdftools::pdf_text("https://www.acf.hhs.gov/sites/default/files/documents/ocse/fy_2018_annual_report.pdf")

# Focus on the table in page 22
pdf_text22 <- strsplit(pdf_text[[22]], "\n")[[1]]

# Reformat the table using "regular expression"
pdf_text22 <- strsplit(pdf_text22, " {2,100}")

# Convert the table in a data frame
pdf_text22 <- plyr::rbind.fill(lapply(pdf_text22, function(x) as.data.frame(t(matrix(x)))))
#下载pdf文件作为R中的变量

谢谢您的帮助s20012303。你的解决方案有效。数据需要清理一下,但至少我和我的电脑都能读取。
# Download the pdf file as a variable in R
pdf_text <- pdftools::pdf_text("https://www.acf.hhs.gov/sites/default/files/documents/ocse/fy_2018_annual_report.pdf")

# Focus on the table in page 22
pdf_text22 <- strsplit(pdf_text[[22]], "\n")[[1]]

# Reformat the table using "regular expression"
pdf_text22 <- strsplit(pdf_text22, " {2,100}")

# Convert the table in a data frame
pdf_text22 <- plyr::rbind.fill(lapply(pdf_text22, function(x) as.data.frame(t(matrix(x)))))