line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::optex::textconv::pdf; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.13'; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
923
|
use v5.14; |
|
1
|
|
|
|
|
3
|
|
6
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
7
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
58
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
7
|
use App::optex::textconv::Converter 'import'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our @CONVERTER = ( |
12
|
|
|
|
|
|
|
[ qr/\.pdf$/i => \&to_text ], |
13
|
|
|
|
|
|
|
); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our %param = ( |
16
|
|
|
|
|
|
|
pagebreak => 'rule', |
17
|
|
|
|
|
|
|
width => 78, |
18
|
|
|
|
|
|
|
mark => '-', |
19
|
|
|
|
|
|
|
format => '[ Page %d ]', |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my %pagebreak = ( |
23
|
|
|
|
|
|
|
rule => sub { |
24
|
|
|
|
|
|
|
my $rule = $param{mark} x $param{width} . "\n\n"; |
25
|
|
|
|
|
|
|
sub { $rule }; |
26
|
|
|
|
|
|
|
}, |
27
|
|
|
|
|
|
|
number => sub { |
28
|
|
|
|
|
|
|
my $n = 1; |
29
|
|
|
|
|
|
|
my $format = $param{format} . "\n\n"; |
30
|
|
|
|
|
|
|
sub { sprintf $format, $n++ }; |
31
|
|
|
|
|
|
|
}, |
32
|
|
|
|
|
|
|
pf => sub { |
33
|
|
|
|
|
|
|
sub { "\f" }; |
34
|
|
|
|
|
|
|
}, |
35
|
|
|
|
|
|
|
); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub to_text { |
38
|
0
|
|
|
0
|
0
|
|
my $file = shift; |
39
|
0
|
0
|
|
|
|
|
my $type = ($file =~ /\.(pdf)$/i)[0] or return; |
40
|
0
|
|
|
|
|
|
my $break = $pagebreak{$param{pagebreak}}->(); |
41
|
0
|
|
|
|
|
|
local $_ = qx{ pdftotext -q \"$file\" - }; |
42
|
0
|
|
|
|
|
|
s/\f/$break->()/ger; |
|
0
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub set { |
46
|
0
|
|
|
0
|
0
|
|
my %opt = @_; |
47
|
0
|
|
|
|
|
|
while (my($k, $v) = each %opt) { |
48
|
0
|
0
|
|
|
|
|
exists $param{$k} or next; |
49
|
0
|
|
|
|
|
|
$param{$k} = $v; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
1; |