簡體   English   中英

在R中使用readPDF(tm軟件包)

[英]Using readPDF in R (tm package)

我是R的初學者,在使用tm軟件包時遇到了一些麻煩。 我需要從第55頁到第300頁中提取特定數據,並認為R可能是這樣做的好方法。 (如果任何人有一個更好的主意,請讓我知道!),我做了一些搜索和安裝后的tm封裝和xpdf包,我已經試過讀 ,並試圖zx8754與沒有運氣的解決方案。 我懷疑這與readPDF命令有關-我得到以下信息:

readPDF(PdftotextOptions =“ -layout”)錯誤:未使用的參數(PdftotextOptions =“ -layout”)

我認為這與嘗試同時使用tm包和xpdf包有關,因此我閱讀了Tony Breyal的解決方案(我不能發布兩個以上的鏈接),將pdfinfo和pdftotext用作環境變量(我在贏8),然后重新啟動。 我確定我丟失了一些東西-現在我在R的工作目錄中有pdftotext.exe。誰能幫助我正確配置此文件,以便tm包正確調用xpdf文件並像應該的readPDF函數?

再次,我對此很陌生,如果我離開的話,我深表歉意。 所有幫助將不勝感激。

提前致謝,

賈斯汀

為了讓您入門,這是讀取PDF文件的完整readPDF命令的示例。 當我嘗試直接從您提供的鏈接中檢索PDF文件時, readPDF引發了錯誤,因此我首先將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] ""    

希望這會幫助您入門。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM