Changeset 10357


Ignore:
Timestamp:
2005-07-29T14:37:55+12:00 (19 years ago)
Author:
chi
Message:

Adding the pdf_to_img routine in convertPDF() function.

File:
1 edited

Legend:

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

    r10282 r10357  
    137137    my $stored_dir = cwd();
    138138    chdir ($dirname) || die "Unable to change to directory $dirname";
     139
    139140    # Select convert utility
    140141    if (!defined $input_type) {
     
    293294
    294295    my $success = 0;
     296    $output_type =~ s/.*\-(.*)/$1/i;
     297    # Attempt coversion to Image
     298    if ($output_type =~ /jp?g|gif|png/i) {
     299    $success = &pdf_to_img($dirname, $input_filename, $output_filestem, $output_type);
     300    if ($success){
     301        return "item";
     302    }
     303    }
    295304
    296305    # Attempt conversion to HTML
     
    335344sub convertPPT {
    336345    my ($input_filename, $output_filestem, $output_type) = @_;
    337 
    338346    my $success = 0;
     347
    339348    my $ppt_convert_type = "";
    340349    if (!$output_type || $windows_scripting ||($output_type !~ /html/i)){
     
    351360           
    352361    $cmd = "";
    353     #if ($timeout) {$cmd = "ulimit -t $timeout;";}
    354     #$cmd .= "$vbScript \"$input_filename\" \"$output_filestem.html\"";
    355     #$cmd .= "$vbScript $input_filename $output_filestem.html";
     362    if ($timeout) {$cmd = "ulimit -t $timeout;";}
    356363    # if the converting directory has already existed
    357364    if (-d $output_filestem) {
     
    377384    $cmd .= " 2>\"$output_filestem.err\""
    378385        if ($ENV{'GSDLOS'} !~ /^windows$/i || $is_winnt_2000);
    379    
     386
    380387    # execute the command
    381388    $!=0;
     
    500507    $cmd .= " 2> \"$output_filestem.err\""
    501508    if ($ENV{'GSDLOS'} !~ /^windows$/i || $is_winnt_2000);
    502    
    503509    # execute the command
    504510    $!=0;
     
    557563}
    558564
     565
    559566# Attempt to convert a word document to html with the word2html scripting program
    560567sub native_doc_to_html {
     
    628635    return 0;
    629636}
    630 
    631 
    632637
    633638# Attempt to convert an RTF document to html with rtftohtml
     
    805810    return 0;
    806811    }
    807    
     812
     813    &util::rm("$output_filestem.err") if (-e "$output_filestem.err");
     814    &util::rm("$output_filestem.out") if (-e "$output_filestem.out");
     815    return 1;
     816}
     817
     818# Convert a pdf file to various types of image with the convert command
     819
     820sub pdf_to_img {
     821    my ($dirname, $input_filename, $output_filestem, $output_type) = @_;
     822 
     823    $cmd = "";
     824    if ($timeout) {$cmd = "ulimit -t $timeout;";}
     825    $output_type =~ s/.*\_(.*)/$1/i;
     826     $cmd .= "perl -S pdftoimg.pl -convert_to $output_type $input_filename $output_filestem";
     827    if ($ENV{'GSDLOS'} !~ /^windows$/i || $is_winnt_2000) {
     828    $cmd .= " > \"$output_filestem.out\" 2> \"$output_filestem.err\"";
     829    } else {
     830    $cmd .= " > \"$output_filestem.err\"";
     831    }
     832
     833    #print STDERR "*** gsConvert pdf_to_img Command =$cmd\n";
     834   
     835    # don't include path on windows (to avoid having to play about
     836    # with quoting when GSDLHOME might contain spaces) but assume
     837    # that the PATH is set up correctly
     838   
     839    $!=0;
     840    my $retval=system($cmd);
     841    if ($retval!=0)
     842    {
     843    print STDERR "Error executing pdftohtml.pl";
     844    if ($!) {print STDERR ": $!";}
     845    print STDERR "\n";
     846    }
     847
     848    #make sure the converter made something
     849    #if ($retval!=0 || ! -s "$output_filestem.html")
     850    #if ($retval !=0) || ! -s "$output_filestem")
     851    if ($retval !=0)
     852    {
     853    &util::rm("$output_filestem.out") if (-e "$output_filestem.out");
     854    #print out the converter's std err, if any
     855    if (-s "$output_filestem.err") {
     856        open (ERRLOG, "$output_filestem.err") || die "$!";
     857        print STDERR "pdftohtml error log:\n";
     858        while (<ERRLOG>) {
     859        print STDERR "$_";
     860        }
     861        close ERRLOG;
     862    }
     863    &util::rm("$output_filestem.html") if (-e "$output_filestem.html");
     864    if (-e "$output_filestem.err") {
     865        if ($faillogfile ne "" && defined(open(FAILLOG,">>$faillogfile")))
     866        {
     867        open (ERRLOG, "$output_filestem.err");
     868        while (<ERRLOG>) {print FAILLOG $_;}
     869        close ERRLOG;
     870        close FAILLOG;
     871       }   
     872        &util::rm("$output_filestem.err");
     873    }
     874    return 0;
     875    }
    808876    &util::rm("$output_filestem.err") if (-e "$output_filestem.err");
    809877    &util::rm("$output_filestem.out") if (-e "$output_filestem.out");
     
    897965    $cmd .= "gs -q -dNODISPLAY -dNOBIND -dWRITESYSTEMDICT -dSIMPLE -c save ";
    898966    $cmd .= "-f ps2ascii.ps \"$input_filename\" -c quit > \"$output_filestem.text\"";
     967    #$cmd .= "pstotext -output \"$output_filestem.text\" $input_filename\"";
    899968    $cmd .= " 2> $output_filestem.err";
    900969    $!=0;
     970
    901971    my $retcode=system($cmd);
    902972    $retcode = $? >> 8;  # see man perlfunc - system for this...
Note: See TracChangeset for help on using the changeset viewer.