(Windows 7/R versione 3.0.1)errore cercando di leggere un PDF utilizzando readPDF dal pacchetto tm
Di seguito i comandi e l'errore risultante:
> library(tm)
> pdf <- readPDF(PdftotextOptions = "-layout")
> dat <- pdf(elem = list(uri = "17214.pdf"), language="de", id="id1")
Error in file(con, "r") : cannot open the connection
In addition: Warning message:
In file(con, "r") :
cannot open file 'C:\Users\Raffael\AppData\Local\Temp
\RtmpS8Uql1\pdfinfo167c2bc159f8': No such file or directory
Come posso risolvere questo problema ?
EDIT ho
(come suggerito da Ben e descritto here)
Ho scaricato Xpdf copiato la versione a 32 bit di C:\Program Files (x86)\xpdf32
e la versione a 64 bit di C:\Program Files\xpdf64
Le variabili d'ambiente pdfinfo
e pdftotext
riferiamo alle rispettive eseguibili sia 32bit (testato con R 32 bit) oa 64 bit (testato con R 64bit)
EDIT II
Un'osservazione molto confuso è che, partendo da una nuova sessione (tm non caricato) l'ultimo comando da solo produrrà l'errore:
> dat <- pdf(elem = list(uri = "17214.pdf"), language="de", id="id1")
Error in file(con, "r") : cannot open the connection
In addition: Warning message:
In file(con, "r") :
cannot open file 'C:\Users\Raffael\AppData\Local\Temp\RtmpKi5GnL
\pdfinfode8283c422f': No such file or directory
non capisco questo a tutti perché la variabile funzione non è definito da tm.readPDF ancora. Qui di seguito troverete la funzione PDF si riferisce a "naturalmente" e di ciò che viene restituito da tm.readPDF:
> pdf
function (elem, language, id)
{
meta <- tm:::pdfinfo(elem$uri)
content <- system2("pdftotext", c(PdftotextOptions, shQuote(elem$uri),
"-"), stdout = TRUE)
PlainTextDocument(content, meta$Author, meta$CreationDate,
meta$Subject, meta$Title, id, meta$Creator, language)
}
<environment: 0x0674bd8c>
> library(tm)
> pdf <- readPDF(PdftotextOptions = "-layout")
> pdf
function (elem, language, id)
{
meta <- tm:::pdfinfo(elem$uri)
content <- system2("pdftotext", c(PdftotextOptions, shQuote(elem$uri),
"-"), stdout = TRUE)
PlainTextDocument(content, meta$Author, meta$CreationDate,
meta$Subject, meta$Title, id, meta$Creator, language)
}
<environment: 0x0c3d7364>
A quanto pare non c'è differenza - allora perché l'uso readPDF a tutti?
EDIT III
il file PDF si trova qui: C:\Users\Raffael\Documents
> getwd()
[1] "C:/Users/Raffael/Documents"
EDIT IV
Prima istruzione di pdf()
è una chiamata a tm:::pdfinfo()
- e c'è l'errore è causato entro le prime righe:
> outfile <- tempfile("pdfinfo")
> on.exit(unlink(outfile))
> status <- system2("pdfinfo", shQuote(normalizePath("C:/Users/Raffael/Documents/17214.pdf")),
+ stdout = outfile)
> tags <- c("Title", "Subject", "Keywords", "Author", "Creator",
+ "Producer", "CreationDate", "ModDate", "Tagged", "Form",
+ "Pages", "Encrypted", "Page size", "File size", "Optimized",
+ "PDF version")
> re <- sprintf("^(%s)", paste(sprintf("%-16s", sprintf("%s:",
+ tags)), collapse = "|"))
> lines <- readLines(outfile, warn = FALSE)
Error in file(con, "r") : cannot open the connection
In addition: Warning message:
In file(con, "r") :
cannot open file 'C:\Users\Raffael\AppData\Local\Temp\RtmpquRYX6\pdfinfo8d419174450': No such file or direc
Apparentemente tempfile()
semplicemente non crea un file.
> outfile <- tempfile("pdfinfo")
> outfile
[1] "C:\\Users\\Raffael\\AppData\\Local\\Temp\\RtmpquRYX6\\pdfinfo8d437bd65d9"
La cartella C:\Users\Raffael\AppData\Local\Temp\RtmpquRYX6
esiste e detiene alcuni file ma nessuno prende il nome pdfinfo8d437bd65d9
.
Hai il tuo 'PATH' pdf2txt configurato correttamente? Vedi qui per i dettagli: https://stat.ethz.ch/pipermail/r-help/2008-November/180201.html – Ben
per favore, dai un'occhiata alla domanda modificata – Raffael