line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package PDF::pdf2json; |
2
|
|
|
|
|
|
|
# ABSTRACT: helper module to retrieve data from pdf2json |
3
|
|
|
|
|
|
|
$PDF::pdf2json::VERSION = '0.002'; |
4
|
1
|
|
|
1
|
|
117667
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
28
|
|
5
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
4
|
use File::Temp; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
78
|
|
8
|
1
|
|
|
1
|
|
5
|
use Path::Class; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
42
|
|
9
|
1
|
|
|
1
|
|
865
|
use Alien::pdf2json; |
|
1
|
|
|
|
|
24347
|
|
|
1
|
|
|
|
|
8
|
|
10
|
1
|
|
|
1
|
|
5499
|
use JSON::MaybeXS; |
|
1
|
|
|
|
|
6722
|
|
|
1
|
|
|
|
|
294
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $alien = Alien::pdf2json->new; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub pdf2json { |
15
|
2
|
|
|
2
|
1
|
2388
|
my ($self, $pdf, %param) = @_; |
16
|
2
|
|
50
|
|
|
18
|
$param{quiet} //= 1; |
17
|
|
|
|
|
|
|
|
18
|
2
|
|
|
|
|
27
|
my $temp_fh = File::Temp->new ( UNLINK => 0 ); |
19
|
2
|
|
|
|
|
1372
|
my @args = (); |
20
|
2
|
100
|
|
|
|
13
|
if( exists $param{page} ) { |
21
|
1
|
50
|
|
|
|
14
|
die "page number must be integer" unless $param{page} =~ /^\d+$/; |
22
|
1
|
|
|
|
|
10
|
push @args, ( '-f', $param{page} ); |
23
|
1
|
|
|
|
|
2
|
push @args, ( '-l', $param{page} ); |
24
|
|
|
|
|
|
|
} |
25
|
2
|
50
|
|
|
|
8
|
if( exists $param{quiet} ) { |
26
|
2
|
50
|
|
|
|
11
|
push @args, '-q' if !!$param{quiet}; |
27
|
|
|
|
|
|
|
} |
28
|
2
|
|
|
|
|
25
|
my $cmd = [ |
29
|
|
|
|
|
|
|
$alien->pdf2json_path, |
30
|
|
|
|
|
|
|
'-enc', 'UTF-8', |
31
|
|
|
|
|
|
|
@args, |
32
|
|
|
|
|
|
|
$pdf, |
33
|
|
|
|
|
|
|
$temp_fh->filename, |
34
|
|
|
|
|
|
|
]; |
35
|
2
|
|
|
|
|
40234
|
my $ret = system( @$cmd ); |
36
|
2
|
50
|
|
|
|
54
|
die "pdf2json failed" if $ret; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# read data from temp file |
39
|
2
|
|
|
|
|
126
|
my $json_data = file( $temp_fh->filename )->slurp(); |
40
|
|
|
|
|
|
|
|
41
|
2
|
|
|
|
|
2017
|
my $data = decode_json( $json_data ); |
42
|
|
|
|
|
|
|
|
43
|
2
|
|
|
|
|
205
|
$data; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
1; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
__END__ |