| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Catmandu::Importer::PDFInfo; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
69781
|
use Catmandu::Sane; |
|
|
1
|
|
|
|
|
188096
|
|
|
|
1
|
|
|
|
|
7
|
|
|
4
|
1
|
|
|
1
|
|
288
|
use Catmandu::Util qw(:is); |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
315
|
|
|
5
|
1
|
|
|
1
|
|
157
|
use Poppler; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use Moo; |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.012'; |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
with 'Catmandu::Importer'; |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has poppler_glib_version => ( |
|
13
|
|
|
|
|
|
|
is => "ro", |
|
14
|
|
|
|
|
|
|
init_arg => undef, |
|
15
|
|
|
|
|
|
|
lazy => 1, |
|
16
|
|
|
|
|
|
|
builder => "_build_poppler_glib_version" |
|
17
|
|
|
|
|
|
|
); |
|
18
|
|
|
|
|
|
|
has has_date_bug => ( |
|
19
|
|
|
|
|
|
|
is => "ro", |
|
20
|
|
|
|
|
|
|
init_arg => undef, |
|
21
|
|
|
|
|
|
|
lazy => 1, |
|
22
|
|
|
|
|
|
|
builder => "_build_has_date_bug" |
|
23
|
|
|
|
|
|
|
); |
|
24
|
|
|
|
|
|
|
has date_offset => ( |
|
25
|
|
|
|
|
|
|
is => "ro", |
|
26
|
|
|
|
|
|
|
init_arg => undef, |
|
27
|
|
|
|
|
|
|
lazy => 1, |
|
28
|
|
|
|
|
|
|
default => sub { |
|
29
|
|
|
|
|
|
|
require DateTime; |
|
30
|
|
|
|
|
|
|
DateTime->now( time_zone => "local" )->offset(); |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
); |
|
33
|
|
|
|
|
|
|
sub _build_poppler_glib_version { |
|
34
|
|
|
|
|
|
|
require ExtUtils::PkgConfig; |
|
35
|
|
|
|
|
|
|
ExtUtils::PkgConfig->modversion('poppler-glib'); |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
sub _build_has_date_bug { |
|
38
|
|
|
|
|
|
|
require version; |
|
39
|
|
|
|
|
|
|
version->parse( $_[0]->poppler_glib_version() ) < version->parse("0.45.0") ? 1 : 0; |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub _createDoc { |
|
43
|
|
|
|
|
|
|
my $self = $_[0]; |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
my $pdf = Poppler::Document->new_from_file( $self->file ); |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
my $record = +{ |
|
48
|
|
|
|
|
|
|
version => $pdf->get_pdf_version_string(), |
|
49
|
|
|
|
|
|
|
title => $pdf->get_title(), |
|
50
|
|
|
|
|
|
|
author => $pdf->get_author(), |
|
51
|
|
|
|
|
|
|
subject => $pdf->get_subject(), |
|
52
|
|
|
|
|
|
|
keywords => $pdf->get_keywords(), |
|
53
|
|
|
|
|
|
|
creator => $pdf->get_creator(), |
|
54
|
|
|
|
|
|
|
producer => $pdf->get_producer(), |
|
55
|
|
|
|
|
|
|
creation_date => $pdf->get_creation_date(), |
|
56
|
|
|
|
|
|
|
modification_date => $pdf->get_modification_date(), |
|
57
|
|
|
|
|
|
|
metadata => $pdf->get_metadata() |
|
58
|
|
|
|
|
|
|
}; |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
if( $self->has_date_bug() ) { |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
if( is_natural( $record->{creation_date} ) ){ |
|
63
|
|
|
|
|
|
|
$record->{creation_date} += $self->date_offset(); |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
if( is_natural( $record->{modification_date} ) ){ |
|
66
|
|
|
|
|
|
|
$record->{modification_date} += $self->date_offset(); |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
$record; |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub generator { |
|
75
|
|
|
|
|
|
|
my ($self) = @_; |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
return sub { |
|
78
|
|
|
|
|
|
|
state $doc; |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
unless($doc){ |
|
81
|
|
|
|
|
|
|
$doc = $self->_createDoc(); |
|
82
|
|
|
|
|
|
|
return $doc; |
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
return; |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
sub DESTROY { |
|
89
|
|
|
|
|
|
|
my ($self) = @_; |
|
90
|
|
|
|
|
|
|
close($self->fh); |
|
91
|
|
|
|
|
|
|
} |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=encoding utf8 |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 NAME |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Catmandu::Importer::PDFInfo - Catmandu importer to extract metadata from one pdf |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# From the command line |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# Export pdf information |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
$ catmandu convert PDFInfo --file input.pdf to YAML |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
#In a script |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
use Catmandu::Sane; |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
use Catmandu::Importer::PDFInfo; |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
my $importer = Catmandu::Importer::PDFInfo->new( file => "/tmp/input.pdf" ); |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
$importer->each(sub{ |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
my $pdf = $_[0]; |
|
118
|
|
|
|
|
|
|
#.. |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
}); |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 EXAMPLE OUTPUT IN YAML |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
author: ~ |
|
125
|
|
|
|
|
|
|
creation_date: 1207274644 |
|
126
|
|
|
|
|
|
|
creator: PDFplus |
|
127
|
|
|
|
|
|
|
keywords: ~ |
|
128
|
|
|
|
|
|
|
metadata: ~ |
|
129
|
|
|
|
|
|
|
modification_date: 1421574847 |
|
130
|
|
|
|
|
|
|
producer: "Nobody at all" |
|
131
|
|
|
|
|
|
|
subject: ~ |
|
132
|
|
|
|
|
|
|
title: "Hello there" |
|
133
|
|
|
|
|
|
|
version: PDF-1.6 |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head1 AUTHORS |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
Nicolas Franck C<< <nicolas.franck at ugent.be> >> |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
L<Catmandu>, L<Catmandu::Importer> , L<Poppler> |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=cut |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
1; |