TheRec
vendredi 8 avril 2005 à 22:01
CODE
<?php
function pdf2string ($sourceFile)
{
$textArray = array ();
$objStart = 0;
$fp = fopen ($sourceFile, 'rb');
$content = fread ($fp, filesize ($sourceFile));
fclose ($fp);
$searchTagStart = chr(13).chr(10).'stream';
$searchTagStartLenght = strlen ($searchTagStart);
while ((($objStart = strpos ($content, $searchTagStart, $objStart)) && ($objEnd = strpos ($content, 'endstream', $objStart+1))))
{
$data = substr ($content, $objStart + $searchTagStartLenght + 2, $objEnd - ($objStart + $searchTagStartLenght) - 2);
$data = @gzuncompress ($data);
if ($data !== FALSE && strpos ($data, 'BT') !== FALSE && strpos ($data, 'ET') !== FALSE)
{
$textArray [] = ExtractText ($data);
}
$objStart = $objStart < $objEnd ? $objEnd : $objStart + 1;
}
return $textArray;
}
function ExtractText ($postScriptData)
{
while ((($textStart = strpos ($postScriptData, '(', $textStart)) && ($textEnd = strpos ($postScriptData, ')', $textStart + 1)) && substr ($postScriptData, $textEnd - 1) != '\\'))
{
$plainText .= substr ($postScriptData, $textStart + 1, $textEnd - $textStart - 1);
if (substr ($postScriptData, $textEnd + 1, 1) == ']') //this adds quite some additional spaces between the words
{
$plainText .= ' ';
}
$textStart = $textStart < $textEnd ? $textEnd : $textStart + 1;
}
return stripslashes ($plainText);
}
?>
J'ai pris ça depuis la doc de PHP :
http://www.php.net/pdfDans les commentaires, "donatas at spurgius dot com 22-Jun-2004 09:56".
Mais j'ai pas testé... good luck !
Sinon, si tu cherche à récupérer les images depuis un PDF, je n'ai rien trouvé de spécial sur le sujet, mais tu dois pouvoir écrire quelque chose en t'aidant des spécifications des standards PDF :
http://cerig.efpg.inpg.fr/Note/2004/pdf.htmC'est une explication simplifié et dans l'encart "En savoir plus sur le format PDF" il y des lients tèr sutiles genre
http://www.sos-pdf.com/ .
Je te laisse regarder, bonne chance !
**Edit**
Appartemment ça ne fonctionne pas..et le correctif que j'ai vu sur la même pas du manuel PDF (commentaires), ne donne pas plus de résultats. Je vais chercher un peu plus, désolé si t'as perdu du temps