Récupérer des contenus textes de fichiers Word, Pdf, Rtf
admin novembre 19th, 2008
Dans un site ou vous désirez que le moteur de recherche soit capable de trouver des textes présent dans des fichiers uploadés ou récupérer le texte pour en faire ce que vous voulez, voici quelques fonctions déclinables à l’infini (puisqu’elles utilisent des applications Linux via la fonction exec()).
// # Pdftotext ################################################### // # Conversion de texte du PDF en Jpeg // # Retour : function Pdftotext($fichier_pdf) { global $tmp_path; $fichier_text=tempnam($tmp_path,'tmpPdftotext'); $commande_transformation="pdftotext -f 1 -l 1 ".$fichier_pdf." ".$fichier_text; $log_commande=exec($commande_transformation); if (is_file($fichier_text)) { $text=file_get_contents($fichier_text); } unlink($fichier_text); return $text; } // # Wordtotext ################################################### // # Conversion de texte du fichier word en texte // # Retour : function Wordtotext($fichier_word) { global $tmp_path; $fichier_text=tempnam($tmp_path,'tmpWordtotext'); $commande_transformation="wvText ".$fichier_word." ".$fichier_text; exec($commande_transformation); if (is_file($fichier_text)) { $text=file_get_contents($fichier_text); } unlink($fichier_text); return $text; } // # Rtftotext ################################################### // # Conversion de texte du fichier rtf en texte // # Retour : function Rtftotext($fichier) { global $tmp_path; $fichier_text=tempnam($tmp_path,'tmpRtftotext'); $commande_transformation="unrtf ".$fichier." >".$fichier_text; exec($commande_transformation); if (is_file($fichier_text)) { $text=file_get_contents($fichier_text); } unlink($fichier_text); return $text; } // # Ppttotext ################################################### // # Conversion de texte du fichier Ppt en texte // # Retour : function Ppttotext($fichier) { global $tmp_path; $fichier_text=tempnam($tmp_path,'tmpRtftotext'); $commande_transformation="catppt ".$fichier." >".$fichier_text; exec($commande_transformation); if (is_file($fichier_text)) { $text=file_get_contents($fichier_text); } unlink($fichier_text); return $text; }
Voici la liste des packages à installer pour disposer de ces fonctions :
- Pdfinfo - http://linux.about.com/library/cmd/blcmdl1_pdfinfo.htm
- Pdftotext - http://www.foolabs.com/xpdf/download.html
- Unrtf lecture de fichiers rtf - http://www.gnu.org/software/unrtf/unrtf.html
- wv lecture de fichier doc - http://wvware.sourceforge.net/
- elinks nécessaire au fonctionnement de wvtext
- catdoc - http://linux.die.net/man/1/catppt
- Du Php
- Comments(2)
salut ,je veux utilisé la fonction Pdftotext de package xpdf,mais je ne sais pas comment installer xpdf sous Windows.
si vous disposez d’une réponse veillez me répondez a travers l’émail : batie_22@hotmail.com
Il faut aller sur le site suivant, télécharger l’archive des fichiers binaires, la décompresser et appeler les executables désirés dans la fonction php en prenant soins de bien indiquer le chemin de l’executable.
http://gnuwin32.sourceforge.net/packages/xpdf.htm