title: Error trying to read a PDF using readPDF from the tm package
body: <p>(Windows 7 / R version 3.0.1)</p>
  
  <p>Below the commands and the resulting error:</p>
  
  <pre><code>&gt; library(tm)
  &gt; pdf &lt;- readPDF(PdftotextOptions = "-layout")
  &gt; dat &lt;- 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
  </code></pre>
  
  <p>How do I solve this issue?</p>
  
  <hr>
  
  <p><strong>EDIT I</strong></p>
  
  <p>(As suggested by Ben and described <a href="https://stat.ethz.ch/pipermail/r-help/2008-November/180064.html" rel="nofollow">here</a>)</p>
  
  <p>I downloaded <a href="http://www.foolabs.com/xpdf/download.html" rel="nofollow">Xpdf</a> copied the 32bit version to 
  <code>C:\Program Files (x86)\xpdf32</code>
  and the 64bit version to 
  <code>C:\Program Files\xpdf64</code></p>
  
  <p>The environment variables <code>pdfinfo</code> and <code>pdftotext</code> are referring to the respective executables either 32bit (tested with R 32bit) or to 64bit (tested with R 64bit)</p>
  
  <hr>
  
  <p><strong>EDIT II</strong></p>
  
  <p>One very confusing observation is that starting from a fresh session (tm not loaded) the last command alone will produce the error:</p>
  
  <pre><code>&gt; dat &lt;- 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
  </code></pre>
  
  <p>I don't understand this at all because the function variable is not defined by tm.readPDF yet. Below you'll find the function pdf refers to "naturally" and to what is returned by tm.readPDF:</p>
  
  <pre><code>&gt; pdf
  
  function (elem, language, id) 
  {
      meta &lt;- tm:::pdfinfo(elem$uri)
      content &lt;- system2("pdftotext", c(PdftotextOptions, shQuote(elem$uri), 
          "-"), stdout = TRUE)
      PlainTextDocument(content, meta$Author, meta$CreationDate, 
          meta$Subject, meta$Title, id, meta$Creator, language)
  }
  &lt;environment: 0x0674bd8c&gt;
  
  &gt; library(tm)
  &gt; pdf &lt;- readPDF(PdftotextOptions = "-layout")
  &gt; pdf
  
  function (elem, language, id) 
  {
      meta &lt;- tm:::pdfinfo(elem$uri)
      content &lt;- system2("pdftotext", c(PdftotextOptions, shQuote(elem$uri), 
          "-"), stdout = TRUE)
      PlainTextDocument(content, meta$Author, meta$CreationDate, 
          meta$Subject, meta$Title, id, meta$Creator, language)
  }
  &lt;environment: 0x0c3d7364&gt;
  </code></pre>
  
  <p>Apparently there is no difference - then why use readPDF at all?</p>
  
  <hr>
  
  <p><strong>EDIT III</strong></p>
  
  <p>The pdf file is located here: <code>C:\Users\Raffael\Documents</code></p>
  
  <pre><code>&gt; getwd()
  [1] "C:/Users/Raffael/Documents"
  </code></pre>
  
  <hr>
  
  <p><strong>EDIT IV</strong></p>
  
  <p>First instruction in <code>pdf()</code> is a call to <code>tm:::pdfinfo()</code> - and there the error is caused within the first few lines:</p>
  
  <pre><code>&gt; outfile &lt;- tempfile("pdfinfo")
  &gt; on.exit(unlink(outfile))
  &gt; status &lt;- system2("pdfinfo", shQuote(normalizePath("C:/Users/Raffael/Documents/17214.pdf")), 
  +                   stdout = outfile)
  &gt; tags &lt;- c("Title", "Subject", "Keywords", "Author", "Creator", 
  +           "Producer", "CreationDate", "ModDate", "Tagged", "Form", 
  +           "Pages", "Encrypted", "Page size", "File size", "Optimized", 
  +           "PDF version")
  &gt; re &lt;- sprintf("^(%s)", paste(sprintf("%-16s", sprintf("%s:", 
  +                                                       tags)), collapse = "|"))
  &gt; lines &lt;- 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
  </code></pre>
  
  <p>Apparently <code>tempfile()</code> simply doesn't create a file.</p>
  
  <pre><code>&gt; outfile &lt;- tempfile("pdfinfo")
  &gt; outfile
  [1] "C:\\Users\\Raffael\\AppData\\Local\\Temp\\RtmpquRYX6\\pdfinfo8d437bd65d9"
  </code></pre>
  
  <p>The folder <code>C:\Users\Raffael\AppData\Local\Temp\RtmpquRYX6</code> exists and holds some files but none is named <code>pdfinfo8d437bd65d9</code>.</p>