line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Importer::PDFPages; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
76694
|
use Catmandu::Sane; |
|
1
|
|
|
|
|
185301
|
|
|
1
|
|
|
|
|
10
|
|
4
|
1
|
|
|
1
|
|
738
|
use Poppler; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
use Moo; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.012'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
with 'Catmandu::Importer'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub generator { |
12
|
|
|
|
|
|
|
my $self = $_[0]; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
return sub { |
15
|
|
|
|
|
|
|
state $pdf; |
16
|
|
|
|
|
|
|
state $page_index; |
17
|
|
|
|
|
|
|
state $num_pages; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
unless($pdf){ |
20
|
|
|
|
|
|
|
$pdf = Poppler::Document->new_from_file( $self->file ); |
21
|
|
|
|
|
|
|
$num_pages = $pdf->get_n_pages(); |
22
|
|
|
|
|
|
|
$page_index = 0; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
if($page_index < $num_pages){ |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $page = $pdf->get_page($page_index); |
28
|
|
|
|
|
|
|
my $text = $page->get_text(); |
29
|
|
|
|
|
|
|
my($w,$h) = $page->get_size; |
30
|
|
|
|
|
|
|
my $label = $page->get_label(); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
my $p = { |
33
|
|
|
|
|
|
|
width => $w, |
34
|
|
|
|
|
|
|
height => $h, |
35
|
|
|
|
|
|
|
label => $label, |
36
|
|
|
|
|
|
|
text => $text |
37
|
|
|
|
|
|
|
}; |
38
|
|
|
|
|
|
|
$page_index++; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
return $p; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
return; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
sub DESTROY { |
49
|
|
|
|
|
|
|
my ($self) = @_; |
50
|
|
|
|
|
|
|
close($self->fh); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=encoding utf8 |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 NAME |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Catmandu::Importer::PDFPages - Catmandu importer to extract text data per page from one pdf |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 SYNOPSIS |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# From the command line |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# Export pdf pages with their text and coördinates |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
$ catmandu convert PDFPages --file input.pdf to YAML |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
#In a script |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
use Catmandu::Sane; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
use Catmandu::Importer::PDFPages; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
my $importer = Catmandu::Importer::PDFPages->new( file => "/tmp/input.pdf" ); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
$importer->each(sub{ |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
my $page = $_[0]; |
78
|
|
|
|
|
|
|
#.. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
}); |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 EXAMPLE OUTPUT IN YAML |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
- label: Cover Page |
85
|
|
|
|
|
|
|
height: 878 |
86
|
|
|
|
|
|
|
width: 595 |
87
|
|
|
|
|
|
|
text: "Hello world" |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 AUTHORS |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Nicolas Franck C<< <nicolas.franck at ugent.be> >> |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 SEE ALSO |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
L<Catmandu>, L<Catmandu::Importer> , L<Poppler> |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=cut |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
1; |