代码之家  ›  专栏  ›  技术社区  ›  DrewConway

从PDF文件中提取文本数据

  •  41
  • DrewConway  · 技术社区  · 14 年前

    是否可以在R中解析PDF文件中的文本数据?在那里 does not appear to be a relevant package for such extraction

    Python there is PDFMiner

    有什么建议吗?

    7 回复  |  直到 8 年前
        1
  •  29
  •   Dirk is no longer here    14 年前

    Linux系统具有 pdftotext 我在这方面取得了相当的成功。默认情况下,它会创建 foo.txt 出于自愿 foo.pdf

    也就是说,文本挖掘包可能有转换器。A quick rseek.org search

        2
  •  26
  •   Remko Duursma    9 年前
        3
  •  9
  •   NiuBiBang juba    12 年前

    一位同事让我开始使用这个方便的开源工具: http://tabula.nerdpower.org/ . 安装、上载PDF,并在PDF中选择需要数据化的表。不是一个直接的解决方案,但肯定比体力劳动好。

        4
  •  9
  •   willallgs    9 年前

    纯R解决方案可以是:

    library('tm')
    file <- 'namefile.pdf'
    Rpdf <- readPDF(control = list(text = "-layout"))
    corpus <- VCorpus(URISource(file), 
          readerControl = list(reader = Rpdf))
    corpus.array <- content(content(corpus)[[1]])
    

    然后在数组中有pdf行。

        5
  •  6
  •   Tung    6 年前
    install.packages("pdftools")
    library(pdftools)
    
    
    download.file("http://www.nfl.com/liveupdate/gamecenter/56901/DEN_Gamebook.pdf", 
                  "56901.DEN.Gamebook", mode = "wb")
    
    txt <- pdf_text("56901.DEN.Gamebook")
    cat(txt[1])
    
        6
  •  5
  •   psychemedia    9 年前

    这个 tabula PDF表格提取器应用程序基于基于Java JAR包的命令行应用程序, tabula-extractor .

    这个 R tabulizer package 提供了一个R包装器,可以轻松地将路径传递到PDF文件,并从数据表中提取数据。

    tabla可以很好地猜测表的位置,但是您也可以通过指定页面的目标区域来告诉它要查看页面的哪个部分。

    可以从多个页面中提取数据,如果需要,可以为每个页面指定不同的区域。

    When Documents Become Databases – Tabulizer R Wrapper for Tabula PDF Table Extractor .

        7
  •  2
  •   Alastair Muir    9 年前

    我使用一个外部实用程序来进行转换,并从R调用它。所有文件都有一个包含所需信息的前导表

    将路径设置为pdftotxt.exe文件并将pdf转换为文本

    exeFile <- "C:/Projects/xpdfbin-win-3.04/bin64/pdftotext.exe"
    
    for(i in 1:length(pdfFracList)){
        fileNumber <- str_sub(pdfFracList[i], start = 1, end = -5)
        pdfSource <- paste0(reportDir,"/", fileNumber, ".pdf")
        txtDestination <- paste0(reportDir,"/", fileNumber, ".txt")
        print(paste0("File number ", i, ", Processing file ", pdfSource))
        system(paste(exeFile, "-table" , pdfSource, txtDestination, sep = " "), wait = TRUE)
    }