Zend - The PHP Company




Miscellaneous

Add Code


PDF Info!  

Type: code fragment
Added by: wbscotta
Entered: 17/03/2000
Last modified: 08/12/1999
Rating: **** (4 votes)
Views: 6578
Have you every tried to get the title or subject of a pdf, only to find that it moved on you? Here's the code that can help you out.


<?php
//Please note that $fileUrl is the path to the pdf 

//Start snippet 
    
$fp fopen($fileUrl"r"); 
    
$buffer ''
    while(!
feof($fp)) { 
      
$buffer .= Beans(fgetc($fp)); 
    } 
    
fclose($fp); 
    
$buffer2 $buffer
    
$buffer2 eregi_replace(">>startxref.*",'',eregi_replace(".*/Info ",'',$buffer2)); 
    
$buffer2 eregi_replace(" R .*",'',$buffer2); 
    
$buffer2 .= " obj<< "
    
$zz strpos($buffer$buffer2); 
    
$buffer substr($buffer$zz); 
    
$buffer eregi_replace("> endobj.*"''$buffer); 
    
$buffer2 $buffer
    
$val1 ''
    
$val2 ''
    if (
eregi(".*[/]Subject [(].*"$buffer2)){ 
      
$val1 eregi_replace("[)][/ >].*"''eregi_replace(".*[/]Subject [(]"''$buffer2)); 
    } 
    if (
eregi(".*[/]Title [(].*"$buffer2)){ 
      
$val2 eregi_replace("[)][/ >].*"''eregi_replace(".*[/]Title [(]"''$buffer2)); 
    } 
    
$buffer stripslashes((strlen($val1) > strlen($val2)?$val1:$val2)); 
//End snippet 


//There is also this function: 
//This function strips out all binary charcters
function Beans ($arg_1) { 
  
$cool=ord($arg_1); 
  
$ret ''
  if ((
$cool 127) & ($cool 31)){ 
    
$ret chr($cool); 
  } 
  return 
$ret
}

//The result is $Buffer with the longest info string (title or subject) from a pdf.
?>


Usage Example




Rate This Script





Search



This Category All Categories