Changeset 25994 for main/trunk/greenstone2/bin/script/pdfpstoimg.pl
- Timestamp:
- 2012-07-19T18:16:46+12:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/bin/script/pdfpstoimg.pl
r25993 r25994 109 109 } else { 110 110 # command execute successfully 111 create_itemfile($output_filestem, $input_basename, $convert_to);111 &util::create_itemfile($output_filestem, $input_basename, $convert_to); 112 112 } 113 113 return 0; 114 }115 116 sub create_itemfile117 {118 my ($output_dir, $convert_basename, $convert_to) = @_;119 opendir(DIR, $output_dir) || die "can't opendir $output_dir: $!";120 121 my $page_num = "";122 my @dir_files = grep {-f "$output_dir/$_"} readdir(DIR);123 124 # Sort files in the directory by page_num125 sub page_number {126 my ($dir) = @_;127 my ($pagenum) =($dir =~ m/^.*[-\.]?(\d+)(\.(jpg|gif|png))?$/i);128 129 $pagenum = 1 unless defined $pagenum;130 return $pagenum;131 }132 133 # sort the files in the directory in the order of page_num rather than lexically.134 @dir_files = sort { page_number($a) <=> page_number($b) } @dir_files;135 136 # work out if the numbering of the now sorted image files starts at 0 or not137 # by checking the number of the first _image_ file (skipping item files)138 my $starts_at_0 = 0;139 my $firstfile = ($dir_files[0] !~ /\.item$/i) ? $dir_files[0] : $dir_files[1];140 if(page_number($firstfile) == 0) { # 00 will evaluate to 0 too in this condition141 $starts_at_0 = 1;142 }143 144 my $item_file = &util::filename_cat($output_dir, $convert_basename.".item");145 open(FILE,">$item_file");146 print FILE "<PagedDocument>\n";147 148 foreach my $file (@dir_files){149 if ($file !~ /\.item/i){150 $page_num = page_number($file);151 $page_num++ if $starts_at_0; # image numbers start at 0, so add 1152 print FILE " <Page pagenum=\"$page_num\" imgfile=\"$file\" txtfile=\"\"/>\n";153 }154 }155 156 print FILE "</PagedDocument>\n";157 closedir DIR;158 return $item_file;159 114 } 160 115
Note:
See TracChangeset
for help on using the changeset viewer.