mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix PDF metadata reading.
This commit is contained in:
parent
80e359ddde
commit
48c39f6144
@ -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)
|
@ -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 );
|
||||
}
|
||||
|
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user