line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CAM::PDF::Annot::Parsed; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
20339
|
use 5.010000; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
36
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
5
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
47
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.09'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
CAM::PDF::Annot::Parsed - Perl extension for pluggable parsing for PDF Annotations |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 SYNOPSIS |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# Define a parsing interface for the annotations |
16
|
|
|
|
|
|
|
package MyYAMLTinyParser; |
17
|
|
|
|
|
|
|
use base qw(YAML::Tiny); |
18
|
|
|
|
|
|
|
# MUST DEFINE parse METHOD!! it takes as input the string contents |
19
|
|
|
|
|
|
|
# of the pdf annotations and must spit out the inflated version of it |
20
|
|
|
|
|
|
|
sub parse { return shift->read_string( shift )->[0] } |
21
|
|
|
|
|
|
|
1; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
package main; |
24
|
|
|
|
|
|
|
my $pdf = CAM::PDF::Annot::Parsed->( 'file.pdf', 'MyYAMLTinyParser' ); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
for my $parsed_annot ( @{$pdf->getParsedAnnots} ) { |
27
|
|
|
|
|
|
|
# Since I am using YAML::Tiny to parse it, each $parsed_annot |
28
|
|
|
|
|
|
|
# is a YAML::Tiny object |
29
|
|
|
|
|
|
|
# if document has annotations with the mask: |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
#author: |
32
|
|
|
|
|
|
|
# name: Donato Azevedo |
33
|
|
|
|
|
|
|
# |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
print $parsed_annot->[0]{author}{name}, "\n"; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 DESCRIPTION |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
This module provides a way to use a pluggable parser to process |
41
|
|
|
|
|
|
|
comments on annotations of PDF documents. Annotations are free |
42
|
|
|
|
|
|
|
text strings generally contained in pop ups for drawing markups |
43
|
|
|
|
|
|
|
of PDF documents. |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=cut |
46
|
|
|
|
|
|
|
|
47
|
1
|
|
|
1
|
|
4
|
use base qw( CAM::PDF::Annot ); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
496
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=item |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Constructor |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
my $p = CAM::PDF::Annot::Parsed->new($file, $parser); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
Creates an instance of the object |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=cut |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub new { |
60
|
1
|
|
|
1
|
1
|
14
|
my ($class, $file, $parser) = @_; |
61
|
1
|
|
|
|
|
12
|
my $self = $class->SUPER::new($file); |
62
|
1
|
|
|
|
|
2633
|
$self->{_parser} = $parser; |
63
|
1
|
|
|
|
|
4
|
bless $self, $class; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=item |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
my $arrRef = $p->getParsedAnnots( $page ); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
Returns a reference to an array containing the objects parsed by $parser (as |
71
|
|
|
|
|
|
|
passed to the constructor). |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=cut |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub getParsedAnnots { |
76
|
1
|
|
|
1
|
0
|
333
|
my ($self, $page) = @_; |
77
|
1
|
|
|
|
|
2
|
my $annots = []; |
78
|
1
|
|
|
|
|
2
|
for my $annot ( @{$self->getAnnotations($page)} ) { |
|
1
|
|
|
|
|
7
|
|
79
|
2
|
|
|
|
|
1171
|
my $annotVal = $self->getValue( $annot ); |
80
|
2
|
100
|
|
|
|
2184
|
if ( exists $annotVal->{Contents} ) { |
81
|
1
|
|
|
|
|
4
|
( my $parse_str = $self->getValue( $annotVal->{Contents} ) ) =~ s/\r\n/\n/g; |
82
|
1
|
50
|
|
|
|
29
|
if ( my $parsed = $self->{_parser}->parse( $parse_str ) ) { |
83
|
1
|
|
|
|
|
1320
|
push @$annots, $parsed; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
} |
87
|
1
|
|
|
|
|
3
|
return $annots; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
1; |
91
|
|
|
|
|
|
|
__END__ |