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