note 77097 modified in ref.pdf by danbrown

[email protected]
Newsgroups php.notes
Message-ID <[email protected]>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.