Stuart Posted June 8, 2011 Share Posted June 8, 2011 Like I said in a previous post I'm using the Zend_Lucene article from your blog to index the text I'm extracting from a number of PDFs. I've managed to get XPDF installed on my local MAMP server and can convert PDF's to text files using this line: exec ("/Applications/MAMP/htdocs/bin/pdftotext -f 1 -l 1 " . $pdf_filename . ".pdf " . $pdf_filename . "1.txt"); From the docs I've found here it says if you supply '-' as the text file name the text will be sent to STDOUT. Should this not mean I can assign that value to a variable like: $text = exec ("/Applications/MAMP/htdocs/bin/pdftotext -f 1 -l 1 " . $pdf_filename . ".pdf -"); or print it out using: echo exec ("/Applications/MAMP/htdocs/bin/pdftotext -f 1 -l 1 " . $pdf_filename . ".pdf -"); Because neither of them seem to work yet converting to a text file does? Do I need to do something else to gain access to the SDTOUT? If you fancy writing a Linux and Apache book I'd buy it! I seem to only be half a LAMP stack developer Link to comment Share on other sites More sharing options...
Larry Posted June 8, 2011 Share Posted June 8, 2011 Check out the PHP manual's page for the exec() function to see how to assign the output of the command to a variable. Or you could use the system() function. Link to comment Share on other sites More sharing options...
Stuart Posted June 8, 2011 Author Share Posted June 8, 2011 Thanks for that Larry I had looked at the manual already but got confused by this example: <?php // outputs the username that owns the running php/httpd process // (on a system with the "whoami" executable in the path) echo exec('whoami'); ?> Hence why I tried to just echo/assign the result of exec - all working now after a closer inspection thanks. Link to comment Share on other sites More sharing options...
Antonio Conte Posted June 8, 2011 Share Posted June 8, 2011 exec ("/Applications/MAMP/htdocs/bin/pdftotext -f 1 -l 1 " . $pdf_filename . ".pdf " . $pdf_filename . "1.txt"); I haven't tried this, but try adding more parameters to the function. <?php $command = "/Applications/MAMP/htdocs/bin/pdftotext -f 1 -l 1 "; exec ($command . $pdf_filename . ".pdf " . $pdf_filename . "1.txt", $return_array, TRUE); foreach ($return_array as $output) { echo $output; } ?> 1 Link to comment Share on other sites More sharing options...
Stuart Posted June 8, 2011 Author Share Posted June 8, 2011 Hi Antonio thanks for that - it is the solution! Like I said above the example in the PHP manual just confused me slightly. Thanks Link to comment Share on other sites More sharing options...
Antonio Conte Posted June 8, 2011 Share Posted June 8, 2011 I'm glad it worked, because it was only an uneducated guess Link to comment Share on other sites More sharing options...
Recommended Posts