1

I have tried the example code recommended in the tm::readPDF documentation:

library(tm)

if(all(file.exists(Sys.which(c("pdfinfo", "pdftotext"))))) {
    uri <- system.file(file.path("doc", "tm.pdf"), package = "tm")
    pdf <- readPDF(PdftotextOptions = "-layout")(elem = list(uri = uri),
                                                 language = "en",
                                                 id = "id1")
    pdf[1:13]
}

But I get the following error (which occurs after calling the function returned by readPDF):

Error in file(con, "r") : cannot open the connection
In addition: Warning message:
In file(con, "r") :
  cannot open file 'C:\DOCUME~1\Tomas\LOCALS~1\Temp\RtmpU33iWo\pdfinfo31c2bd5762a': No such file or directory

Note that I have installed all xpdf binaries to current directory (but this is handled by the if condition).

EDIT: found out this is a bug. What would be the easiest workaround?

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
Tomas
  • 57,621
  • 49
  • 238
  • 373
  • Easy workaround: http://stackoverflow.com/questions/17979074/error-trying-to-read-a-pdf-using-readpdf-from-the-tm-package/17981259#17981259 – Ben Aug 06 '13 at 14:35

1 Answers1

3

Did some debugging and see it fails in tm:::pdfinfo():

status <- system2("pdfinfo", shQuote(normalizePath(file)), 
        stdout = outfile)

This command doesn't create the outfile. According to Redirect system2 stdout to a file on windows this is a bug!

Community
  • 1
  • 1
Tomas
  • 57,621
  • 49
  • 238
  • 373