note 77097 modified in ref.pdf by danbrown
| From: | danbrown@php.net | Date: | Thu, 09 Oct 2008 12:48:03 +0000 |
| Subject: | note 77097 modified in ref.pdf by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-145206@lists.php.net to get a copy of this message | ||
I seriously tried to get PDF parsing to work to use it in the indexing for fulltext search for a
document management. But none of the pdf2text functions below worked for my test cases (among them
an openoffice generated pdf file and a file generated by fpdf).
But I found a REALLY WORKING SOLUTION! On linux systems, install the XPDF package. It comes with a
tool called pdftotext. Use php code similar to the following to get the text content of your pdf
files:
<?php
$file = "test.pdf";
$outpath = preg_replace("/\.pdf$/", "", $file).".txt";
system("pdftotext ".escapeshellcmd($file), $ret);
if ($ret == 0)
{
$value = file_get_contents($outpath);
unlink($outpath);
print $value;
}
if ($ret == 127)
print "Could not find pdftotext tool.";
if ($ret == 1)
print "Could not find pdf file.";
?>
The solution works on all test cases and is much more powerful than any of the previous pure php
functions posted here, although only available on linux.
--was--
I seriously tried to get PDF parsing to work to use it in the indexing for fulltext search for a
document management. But none of the pdf2text functions below worked for my test cases (among them
an openoffice generated pdf file and a file generated by fpdf).
But I found a REALLY WORKING SOLUTION! On linux systems, install the XPDF package. It comes with a
tool called pdftotext. Use php code similar to the following to get the text content of your pdf
files:
<?
$file = "test.pdf";
$outpath = preg_replace("/\.pdf$/", "", $file).".txt";
system("pdftotext ".escapeshellcmd($file), $ret);
if ($ret == 0)
{
$value = file_get_contents($outpath);
unlink($outpath);
print $value;
}
if ($ret == 127)
print "Could not find pdftotext tool.";
if ($ret == 1)
print "Could not find pdf file.";
?>
The solution works on all test cases and is much more powerful than any of the previous pure php
functions posted here, although only available on linux.
http://php.net/manual/en/ref.pdf.php