note 96467 added to ref.pdf
| From: | AbdoulayeSiby at osu1 dot php dot net | Date: | Mon, 01 Mar 2010 02:14:45 +0000 |
| Subject: | note 96467 added to ref.pdf | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-166455@lists.php.net to get a copy of this message | ||
Hello there
I would like to say that the suggestion from Sam from dogmaConsult.de works well.
The only limitation, wich I find trivial, is that some servers may be configured in a way that may
prevent the creation of new files in the web folders unless the process creating the file is Apache
or any of its related modules (PHP, ...). Your best bet will be to use the /tmp/ folder or any
temporary folder to which the linux command that you are running through PHP (in this case
pdftotext) has access.
Here is my code. Note that I have used the -layout option. That instructs pdftotext to keep the
original physical layout of the text content of the PDF. The result is amazing. I invite you to try
it. Such wonderful application should be ported to PHP as an extension. Even table layout are
preserved. I have tried converting a calendar form PDF to text and it was readable and not messy at
all.
<?php
$file = "Sample.pdf";
$outpath = preg_replace("/\.pdf$/", "", $file).".txt";
$escaped = escapeshellcmd($file);
exec("pdftotext -layout $escaped /tmp/$outpath");
$output = file_get_contents("/tmp/$outpath");
echo "<pre>$output</pre>";
?>
Cheers
Abdoulaye Siby
asiby _at_ hotmail _dot_com
----
Server IP: 80.67.10.226
Probable Submitter: 132.213.238.200
----
Manual Page -- http://www.php.net/manual/en/ref.pdf.php
Edit -- https://master.php.net/note/edit/96467
Del: integrated -- https://master.php.net/note/delete/96467/integrated
Del: useless -- https://master.php.net/note/delete/96467/useless
Del: bad code -- https://master.php.net/note/delete/96467/bad+code
Del: spam -- https://master.php.net/note/delete/96467/spam
Del: non-english -- https://master.php.net/note/delete/96467/non-english
Del: in docs -- https://master.php.net/note/delete/96467/in+docs
Del: other reasons-- https://master.php.net/note/delete/96467
Reject -- https://master.php.net/note/reject/96467
Search -- https://master.php.net/manage/user-notes.php