Changeset 22871


Ignore:
Timestamp:
2010-09-07T14:05:36+12:00 (11 years ago)
Author:
kjdon
Message:

added code to generate an item file if asked for pagedimg output with openoffice. Have to tidy up the generated HTML files so remove unnecessary links

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/plugins/PowerPointPlugin.pm

    r22861 r22871  
    197197    #is this true??
    198198    push(@$specific_options,"-input_encoding", "utf8");
     199    if ($self->{'openoffice_conversion'}) {
     200        push(@$specific_options, "-create_thumbnail", "false", "-create_screenview", "false");
     201    }
    199202    }
    200203
     
    259262    #print STDERR "result = $result\n";
    260263    if ($self->{'convert_to'} eq "pagedimg") {
    261         #my $item_filename = $self->generate_item_file($new_filename);
    262         #return $item_filename;
    263         return "/research/kjdon/home/gsdl/collect/openoffice/test.item";
     264        my $item_filename = $self->generate_item_file($new_filename);
     265        return $item_filename;
    264266    }
    265267    return $new_filename;
     
    301303}
    302304
     305sub generate_item_file
     306{
     307    my $self = shift(@_);
     308    my ($input_filename) = @_;
     309    my $outhandle = $self->{'outhandle'};
     310    my ($tailname, $dirname, $suffix)
     311    = &File::Basename::fileparse($input_filename, "\\.[^\\.]+\$");
     312
     313    # find all the files in the directory
     314    if (!opendir (DIR, $dirname)) {
     315    print $outhandle "PowerPointPlugin: Couldn't read directory $dirname\n";
     316    return $input_filename;
     317    }
     318
     319    my @dir = readdir (DIR);
     320    closedir (DIR);
     321
     322    # start the item file
     323    my $itemfile_name = &util::filename_cat($dirname, "$tailname.item");
     324
     325    # encoding specification????
     326    if (!open (ITEMFILE, ">$itemfile_name")) {
     327    print $outhandle "PowerPOintPlugin: Couldn't open $itemfile_name for writing\n";
     328    }
     329    print ITEMFILE "<GeneratedBy>PowerPointPlugin\n";
     330    # print the first page
     331    my @sorted_dir = sort alphanum_sort @dir;
     332    for (my $i = 0; $i < scalar(@sorted_dir); $i++) {
     333    my $file = $sorted_dir[$i];
     334    if ($file =~ /^img(\d+)\.jpg$/) {
     335        my $num = $1;
     336        $self->tidy_up_html(&util::filename_cat($dirname, "text$num.html"));
     337        print ITEMFILE "$num:img$num.jpg:text$num.html:\n";
     338    }
     339    }
     340    close ITEMFILE;
     341    return $itemfile_name;
     342
     343   
     344}
     345
     346# want to sort img1, img2, ...img10, img11 etc.
     347sub alphanum_sort {
     348   
     349    my ($a_txt, $a_num) = $a =~ /^([^\d]*)(\d*)/;
     350    my ($b_txt, $b_num) = $b =~ /^([^\d]*)(\d*)/;
     351   
     352    if ($a_txt ne $b_txt) { return ($a cmp $b) };
     353    return ($a_num <=> $b_num);
     354}
     355
     356# Want to remove the line that links to first page, last page, next page, text etc.
     357sub tidy_up_html {
     358
     359    my $self = shift(@_);
     360    my ($filename) = @_;
     361    return unless (-f $filename);
     362    my $backup_filename = "$filename.bak";
     363
     364    &File::Copy::copy($filename, $backup_filename);
     365
     366    open (ORIGINAL, $backup_filename) || return;
     367    open(HTMLFILE, ">$filename") || return;
     368
     369    my $line ="";
     370    while ($line = <ORIGINAL>) {
     371    if ($line =~ /\<body\>/) {
     372        print HTMLFILE $line;
     373        $line = <ORIGINAL>;
     374        next if $line =~ /\<center\>/;
     375    }
     376    next if $line =~ /First page/;
     377    print HTMLFILE ($line);
     378    }
     379
     380    close HTMLFILE;
     381    close ORIGINAL;
     382}
    3033831;
    304384
Note: See TracChangeset for help on using the changeset viewer.