Convertir un fichier pdf en html

Lilly
Invité n'ayant pas de compte PHPfrance

13 déc. 2010, 22:32

Bonjour,

J'aimerai savoir comment convertir un pdf en html avec php.
Existe-t-il une librairie?

Merci

ViPHP
xTG
ViPHP | 7331 Messages

13 déc. 2010, 23:42

Le seul truc que j'ai trouvé en PHP :
<?php
 
//1-download fichier à http://www.pdflib.com/download/tet/ (version windows xp 32 bits, TET-4.0p2-MSWin32.msi)
//2-installer sur un ordi, pas obliger d'être le serveur
//3-aller C:\Program Files (x86)\PDFlib\TET 4.0p2 32-bit\bind\php, il y a les versions de php
//4-prendre libtet_php.dll dans le bon répertoire représentant la version de php installé
//5-mettre ce fichier dans le répertoire de php\ext et modifier php.ini pour mettre extension=libtet_php.dll
// il doit y avoir une section TET lorsqu'on fait php phpinfo();  
 
 
// ***   $Id: extractor.php,v 1.11 2010/07/21 19:58:35 rjs Exp $ Simple PDF text extractor based on PDFlib TET   ***
$globaloptlist = "searchpath={../data ../../data ../../../resource/cmap}"; //global option list
$docoptlist = "";       // document-specific option list
$pageoptlist = "granularity=page";     // page-specific option list
$separator = "\n";    // separator to emit after each chunk of text. This depends on the application's needs; for granularity=word a space character may be useful
 
$pageno = 0;
 
try {
 
    $tet = new TET();
 
//mettre ici les infos nécessaire
$filepdf = file_get_contents('http://www.irs.gov/pub/irs-pdf/fw4.pdf'); //adresse web du fichier PDF
$pvf_filename = "/pvf/virt.pdf";     //nom du fichier virtuel, peux laisser tel quel
$tet->create_pvf($pvf_filename, $filepdf,"" );    //ici c'est la création dufichier virtuel, donc pas touche
$infilename = $pvf_filename;
$outfilename = "fichier.txt";      //nom du fichier de sortie
 
 
    if (!$outfp = fopen("$outfilename", "wb" )) {
 die("Couldn't open output file '" . $outfilename . "'\n" );
    }
 
 
    $tet->set_option($globaloptlist);
 
    $doc = $tet->open_document($infilename, $docoptlist);
 
    if ($doc == -1) {
 die("Error ". $tet->get_errnum() . " in " . $tet->get_apiname()
     . "(): " . $tet->get_errmsg() . "\n" );
    }
 
    /* get number of pages in the document */
    $n_pages = $tet->pcos_get_number($doc, "length:pages" );
 
    /* loop over pages in the document */
    for ($pageno = 1; $pageno <= $n_pages; ++$pageno) {
 
 $page = $tet->open_page($doc, $pageno, $pageoptlist);
 
 if ($page == -1) {
     print("Error ". $tet->get_errnum() ." in ". $tet->get_apiname()
  . "(): " . $tet->get_errmsg() . "\n" );
     next;                        /* try next page */
 }
 
 /* Retrieve all text fragments; This is actually not required
  * for granularity=page, but must be used for other granularities.
  */
 while (($text = $tet->get_text($page)) != "" ) {
 
     fwrite($outfp, $text);  /* print the retrieved text */
 
     /* print a separator between chunks of text */
     fwrite($outfp, $separator);
 }
 
 
 if ($tet->get_errnum() != 0) {
     print("Error ". $tet->get_errnum() . " in " .  
      $tet->get_apiname() . "(): on page $pageno"  
      . $tet->get_errmsg() . "\n" );
 }
 
 $tet->close_page($page);
    }
 
    fclose($outfp);
 
    $tet->close_document($doc);
}
catch (TETException $e) {
    if ($pageno == 0) {
 die("TET exception occurred in extractor sample:\n" .
     "[" . $e->get_errnum() . "] " . $e->get_apiname() . ": " .
     $e->get_errmsg() . "\n" );
    } else {
 die("TET exception occurred in extractor sample:\n" .
     "[" . $e->get_errnum() . "] " . $e->get_apiname() .
     "on page $pageno: " .  $e->get_errmsg() . "\n" );
    }
}
catch (Exception $e) {
    die($e);
}
 
$tet = 0;
 
?>
Source : http://forum.hardware.fr/hfr/Programmat ... 6416_1.htm

Eléphant du PHP | 209 Messages

14 déc. 2010, 07:52

Sauf que pdflib, c'est pas libre...

Dans le Zend Framework, il y a une bibliothèque de lecture de PDF qui marchouille dans certain cas (mais qui ne fait pas la traduction automatique en HTML)
--
Eric

ViPHP
ViPHP | 3607 Messages

14 déc. 2010, 12:11

Bon ben comme d'habitude google... :-°
https://encrypted.google.com/search?hl= ... =&gs_rfai=

Lilly
Invité n'ayant pas de compte PHPfrance

15 déc. 2010, 13:44

Ok merci
Comment faire pour convertir un fichier Word en php?

Merci d'avance

Lilly
Invité n'ayant pas de compte PHPfrance

15 déc. 2010, 14:36

un fichier word en html!

ViPHP
xTG
ViPHP | 7331 Messages

15 déc. 2010, 16:13

Quel format word ?
Le plus simple reste d'avoir des documents word enregistrés au format WordML qui se rapporte à un syntaxe XML.
Il ne reste plus qu'à utiliser des fonctions PHP travaillant le xml.

Lilly
Invité n'ayant pas de compte PHPfrance

15 déc. 2010, 16:17

c'est du format .doc

Vous me conseillez quoi alors?

ViPHP
xTG
ViPHP | 7331 Messages

15 déc. 2010, 18:01

De faire une recherche sur un moteur de recherche...
Il existe une floppée de logiciels qui font ce que tu demandes, et peut être même dans le tas des solutions web qui ne nécessitent pas d'accès serveur total.