note 96467 deleted from ref.pdf by danbrown
| From: | danbrown@php.net | Date: | Mon, 01 Mar 2010 16:00:32 +0000 |
| Subject: | note 96467 deleted from ref.pdf by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-166496@lists.php.net to get a copy of this message | ||
Note Submitter: Abdoulaye Siby
----
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