sub gettitle { use Fcntl; my $file = shift; local *IN; sysopen( IN, $file, O_RDONLY, 0 ) or die "while reading: '$file'\n"; read IN, my ($str), -s $file; close IN; my ($info_block) = ( $str =~ /\/Info\s(\d+)\s0\sR/ ) or die "cannot get /Info paragraph\n"; my $searchpos = -1; my $info_start; while (1) { $info_start = index( $str, "$info_block 0 obj", $searchpos + 1 ); die "cannot get position of '$info_block 0 obj'\n" if $info_start < $searchpos + 1; last if ( substr( $str, $info_start - 1, 1 ) =~ /\015|\012/ ); $searchpos = $info_start; } my $info_obj = substr( $str, $info_start, index( $str, ">>", $info_start ) - $info_start + 2 ); my ($title) = ( $info_obj =~ /\/Title\s*\( ([^\015\012|\015|\012]*) \) /x ) or return 'undefined'; return $title; }