Changeset 10402


Ignore:
Timestamp:
2005-08-03T12:38:29+12:00 (19 years ago)
Author:
chi
Message:

Modifications to consider the different generated file names under windows and linux system. Also,
to convert the PDF documents to gif needs to be dealt with differently as the default conversion
converts the documents to GIF animation.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/bin/script/pdftoimg.pl

    r10358 r10402  
    6060    if (!parsargv::parse(\@ARGV,
    6161             'convert_to/.*/^', \$convert_to,
    62              ))
    63     {
    64     print_usage();
     62             )) {
     63        print_usage();
    6564    }
    6665   
     
    8685    exit(1);
    8786    }
    88 
    89     # Check that ImageMagick is installed and available on the path (except for Windows 95/98)
    90     if (!($ENV{'GSDLOS'} eq "windows" && !Win32::IsWinNT())) {
    91     my $result = `identify 2>&1`;
    92     if ($? == -1 || $? == 256) {  # Linux and Windows return different values for "program not found"
    93         $self->{'imagemagick_not_installed'} = 1;
    94         #ImageMagick is not installed, thus the convert utility is not available.
    95         print STDERR "*** ImageMagick is not installed, the convert utility is not available\n";
    96         return 1;
    97     }
    98     }
    99     my $cmd = "convert";
    100 
    10187    # don't include path on windows (to avoid having to play about
    10288    # with quoting when GSDLHOME might contain spaces) but assume
    10389    # that the PATH is set up correctly.
    104     $cmd = "convert" if ($ENV{'GSDLOS'} =~ /^windows$/);
    105     $cmd .= " ".$input_filename." ".$output_filestem."/".$input_basename.".".$convert_to;
    106     #$cmd .= " \"$input_filename\" -c quit > \"$output_filestem.text\"";
    107 
    108     print STDERR "*** pdftoImge Command = $cmd\n";
    109 
     90    $cmd = "convert";
     91    #if ($ENV{'GSDLOS'} =~ /^windows$/);
     92    #Convert utility will convert the PDF to GIF Animation
     93    if ($convert_to eq "gif") {
     94    if ($ENV{'GSDLOS'} =~ /^windows$/){
     95        $cmd .= " ".$input_filename." ".$output_filestem."\\".$input_basename."-%02d.".$convert_to;
     96    } else {
     97        $cmd .= " ".$input_filename." ".$output_filestem."/".$input_basename."-%02d.".$convert_to;
     98    }
     99    } else {
     100    if ($ENV{'GSDLOS'} =~ /^windows$/){
     101        $cmd .= " ".$input_filename." ".$output_filestem."\\".$input_basename.".".$convert_to;
     102    } else {
     103        $cmd .= " ".$input_filename." ".$output_filestem."/".$input_basename.".".$convert_to;
     104    }
     105    }   
     106 
    110107    # system() returns -1 if it can't run, otherwise it's $cmds ret val.
    111108    # note we return 0 if the file is "encrypted"
     
    119116    } else {
    120117    # command execute successfully
    121     create_itemfile($output_filestem, $input_basename);
     118    create_itemfile($output_filestem, $input_basename, $convert_to);
    122119    }
    123120    return 0;
     
    126123sub create_itemfile
    127124{
    128     my ($output_dir, $convert_basename) = @_;
     125    my ($output_dir, $convert_basename, $convert_to) = @_;
    129126    opendir(DIR, $output_dir) || die "can't opendir $output_dir: $!"; 
    130127    my $item_file = $output_dir."/".$convert_basename.".item";
     
    139136    sub page_num {
    140137    my ($dir) = @_;
    141     my ($page_num) =($dir =~ m/^.*-(\d+)\.(.*)$/i);
    142     return $page_num;
     138    my $pagenum = "";
     139    if ($ENV{'GSDLOS'} =~ /^windows$/){
     140       ($pagenum) =($dir =~ m/^.*\.(\d+)$/i);   
     141    } else {
     142       ($pagenum) =($dir =~ m/^.*-(\d+)\.(.*)$/i);
     143    }
     144    $pagenum = $pagenum || 1;
     145    return $pagenum;
    143146    }
    144147
     
    147150
    148151    foreach my $file (@dir_files){
    149     $file =~ m/^.*-(\d+)\.(.*)$/i;
    150 
     152        if ($ENV{'GSDLOS'} =~ /^windows$/ && $convert_to ne "gif"){
     153      ($page_num) =($file =~ m/^.*\.(\d+)$/i);
     154    } else {
     155        ($page_num) =($file =~ m/^.*-(\d+)\.(.*)/i);   
     156    }
    151157    # as the converter will convert the document to image files start from page 0
    152     $page_num = $1+1;
     158    $page_num =$page_num + 1 if defined $page_num;
    153159    $page_num = 1 unless defined $page_num;
    154    
    155160    if ($file !~ /\.item/i){
    156161        print FILE "   <Page pagenum=\"$page_num\" imgfile=\"$file\" txtfile=\"\"/>\n";
    157162    }
    158163    }
     164
    159165    print FILE "</PagedDocument>\n";
    160166    closedir DIR;
     
    165171exit (&main(@ARGV));
    166172
     173
     174
Note: See TracChangeset for help on using the changeset viewer.