1 #!/usr/bin/perl -- # -*- Perl -*-
3 # this needs some cleanup...
5 my $PSTOTEXT = "pstotext";
11 open (F, "$PSTOTEXT $pdf |");
17 $inindex = 1 if /^<index/;
20 $index .= $_ if /^\s*</;
25 while ($index =~ /^(.*?)((<phrase role=\"pageno\">.*?<\/phrase>\s*)+)/s) {
30 my @pages = m/<phrase role=\"pageno\">.*?<\/phrase>\s*/sg;
35 foreach my $page (@pages) {
36 my $pageno = &pageno($page);
37 if ($pageno =~ /^([0-9]+)[^0-9]([0-9]+)$/) { # funky -
38 for (my $count = $1; $count <= $2; $count++) {
39 push (@mpages, "<phrase role=\"$pageno\">$count</phrase>");
42 push (@mpages, $page);
45 @pages = sort rangesort @mpages;
48 # Remove duplicates...
52 foreach my $page (@pages) {
53 my $pageno = &pageno($page);
54 if ($pageno ne $current) {
55 push (@mpages, $page);
67 my $len = &rangelen($count, @pages);
69 my $page = shift @pages;
70 push (@cpages, $page);
72 my $fpage = shift @pages;
75 $lpage = shift @pages;
78 my $fpno = &pageno($fpage);
79 my $lpno = &pageno($lpage);
80 $fpage =~ s/>$fpno</>${fpno}-$lpno</s;
81 push (@cpages, $fpage);
87 my $page = shift @pages;
103 $page =~ s/^<phrase.*?>//;
104 $page =~ s/^<link.*?>//;
106 return $1 if $page =~ /^([^<>]+)/;
111 my $apno = &pageno($a);
112 my $bpno = &pageno($b);
114 # Make sure roman pages come before arabic ones, otherwise sort them in order
115 return -1 if ($apno !~ /^\d+/ && $bpno =~ /^\d+/);
116 return 1 if ($apno =~ /^\d+/ && $bpno !~ /^\d+/);
117 return $apno <=> $bpno;
126 my $current = &pageno($pages[$count]);
127 while ($count < $#pages && $inrange) {
129 my $next = &pageno($pages[$count]);
130 if ($current + 1 eq $next) {