Fix PDF metadata reading.

This commit is contained in:
Kovid Goyal 2007-08-24 23:46:57 +00:00
parent 80e359ddde
commit 48c39f6144
3 changed files with 2 additions and 51 deletions

View File

@ -68,4 +68,4 @@ class MetaInformation(object):
return ans.strip()
def __nonzero__(self):
return self.title or self.author or self.comments or self.category
return bool(self.title or self.author or self.comments or self.category)

View File

@ -1,49 +0,0 @@
#!/usr/bin/perl
# Read/Write PDF meta data
# Based on pdf-meta from http://www.osresearch.net/wiki/index.php/Pdf-meta
use warnings;
use strict;
use PDF::API2;
use Getopt::Long;
use Data::Dumper;
my %new_info = (Creator => 'libprs500.metadata', CreationDate => scalar( localtime ),);
GetOptions(
"c|creator=s" => \$new_info{Creator},
"d|date=s" => \$new_info{CreationDate},
"p|producer=s" => \$new_info{Producer},
"a|author=s" => \$new_info{Author},
"s|subject=s" => \$new_info{Subject},
"k|keywords=s" => \$new_info{Keywords},
"t|title=s" => \$new_info{Title},
) or die "Usage: (no help yet!)\n";
for my $file (@ARGV)
{
my $pdf = PDF::API2->open( $file )
or warn "Unable to open $file: $!\n"
and next;
my %info = $pdf->info;
for my $key (keys %info)
{
print $key.' = """'.$info{$key}.'"""'."\n";
}
print "\n";
for my $key (keys %new_info)
{
my $new_value = $new_info{$key};
next unless defined $new_value;
$info{$key} = $new_value;
}
$pdf->info( %info );
$pdf->saveas( $file );
}

View File

@ -56,7 +56,7 @@ def set_metadata(path, options):
return True
def get_metadata_from_file(path, default_mi=None):
if not default_mi:
if default_mi is None:
title = os.path.splitext(os.path.basename(path))[0]
mi = MetaInformation(title, 'Unknown')
else: