title: Converting pdf files to txt files with php
body: <p>There's this program, pdftotext, that can convert a pdf file to a text file. To use it directly on the linux console:</p>
  
  <pre><code>pdftotext file.pdf
  </code></pre>
  
  <p>That will generate a file.txt on the same directory as the pdf file. I was looking for a way to do it from inside a php program, and after some googling I ended with two commands that should work for me: <em>system()</em> and <em>exec()</em>. So I made a php file with this:</p>
  
  <pre><code>&lt;?php
      system('pdftotext file.pdf');
  ?&gt;
  </code></pre>
  
  <p>But when I run this code, it doesn't work. No txt file is created.
  So I tried to create a test file with another command:</p>
  
  <pre><code>&lt;?php
      system('touch test.txt');
  ?&gt;
  </code></pre>
  
  <p>This worked fine. I've also used exec() and the results were the same. Why doesn't it work?</p>
  
  <p><strong>EDIT:</strong> following RoBorg advice, i added the 2>&amp;1 argument to the command, so:</p>
  
  <pre><code>&lt;?php
      system('pdftotext file.pdf 2&gt;&amp;1');
  ?&gt;
  </code></pre>
  
  <p>it printed a error message:</p>
  
  <blockquote>
    <p>pdftotext: error while loading shared
    libraries: libfontconfig.so.1: cannot
    open shared object file: No such file
    or directory</p>
  </blockquote>
  
  <p>Seems like something is missing on the server.</p>