<?php function openPDF($filename){ $handle = fopen($filename,"rb"); $content = fread($handle, filesize($filename)); fclose($handle); return $content; } function versionPDF($content){ $p1 = strpos($content,'%')+1; $p2 = strpos($content,'%',$p1)-2; $version=substr($content,$p1,$p2); return strcmp(trim($version),'PDF-1.4'); } function getPDFDate($type){ if (strcmp($type,'cre')==0) $input = '/CreationDate'; if (strcmp($type,'mod')==0) $input = '/ModDate'; global $content; $p1 = strpos($content,$input)+1; $p2 = strpos($content,0x2F,$p1); $line = substr($content,strlen($input)+$p1,$p2-$p1-2-strlen($input)); $row = substr($line,2,14); $date = date('l, d F Y H:i:s',mktime(substr($row,8,2),substr($row,10,2),substr($row,12,2),substr($row,4,2),substr($row,6,2),substr($row,0,4))); return $date; } function getPDFInfo($type){ if (strcmp($type,'tit')==0) $input = '/Title'; if (strcmp($type,'cre')==0) $input = '/Creator'; if (strcmp($type,'aut')==0) $input = '/Author'; if (strcmp($type,'key')==0) $input = '/Keywords'; if (strcmp($type,'sub')==0) $input = '/Subject'; global $content; $p1 = strpos($content,$input)+1; if (strcmp($type,'sub')==0){ $s1 = '>>';$s2 = 1;} else{ $s1 = 0x2F; $s2 = 2;} $p2 = strpos($content,$s1,$p1); $line = substr($content,strlen($input)+$p1,$p2-$p1-$s2-strlen($input)); $line = preg_replace("/\[0-9]{3}/",'',$line); if (trim($line)=='') $line = '(non renseigné)'; return $line; } function getPDFContent($content,$start,$end){ $s1 = 0; $e1 = 0; $objc = array(); while ($s1 !== false && $e1 !== false){ $s1 = strpos($content,$start,$e1)+(strlen($start)+1); if ($s1 !== false){ $e1 = strpos($content,$end,$s1); if ($e1 !== false) $objc[] = substr($content,$s1,$e1-$s1); } } return $objc; } function extractText($content){ $obj = array(); $ret = array(); $mots = array(); preg_match_all(''[([^]]+)]TJ'', $content, $obj); for ($i=0;$i<count($obj[0])-1;$i++){ preg_match_all(''((.){1})'', $obj[1][$i], $mots[$i]); $ret[] = implode('',$mots[$i][1]); } $ret = implode(' ',$ret); return $ret; } function getPDFText($content){ $gc = getPDFContent($content,'obj','endobj'); $gc_size = count($gc); $streams = array(); for ($i=0;$i<$gc_size;$i++){ $sc = getPDFContent($gc[$i],'stream','endstream'); if (!empty($sc)){ $streams[] = $sc; } } if (count($streams)>0){ return extractText(gzuncompress(trim($streams[0][0]))); } } /************************************/ // 1. Ouverture du PDF $filename = 'test.pdf'; $content = openPDF($filename); // 2. Vérification de la version du PDF - seule 1.4 est supportée if (versionPDF($content)!=0) echo 'Cette source n'est pas été conçue/testée pour d'autres versions que la version PDF-1.4.<br />Votre fichier a la version '.$version.', désolé'; else{ // 3. Récupération des propriétés CreationDate, ModDate, Title, Creator, Author, Keywords et Subject $creDate = getPDFDate('cre'); echo 'Date de création: '.$creDate.'<br />'; $modDate = getPDFDate('mod'); echo 'Date de modification: '.$modDate.'<br />'; $title = getPDFInfo('tit'); echo 'Titre du fichier: '.$title.'<br />'; $creator = getPDFInfo('cre'); echo 'Création du fichier: '.$creator.'<br />'; $author = getPDFInfo('aut'); echo 'Auteur: '.$author.'<br />'; $keywords = getPDFInfo('key'); echo 'Mots clés: '.$keywords.'<br />'; $sujet = getPDFInfo('sub'); echo 'Sujet: '.$sujet.'<br /><br />'; //4. Récupération du contenu du PDF $contenu = getPDFText($content); echo 'Contenu textuel:<br />'.$contenu; } ?>
Avis de décès, Carte de voeux, Bricolage, Coloriages, Cinéma, Coiffure, Cuisine, Déco, Dictionnaire, Horoscope, Jeux en ligne, Programme TV, Recettes, Restaurant, SMIC, Test débit, Voyage, Signification prénom