| 1 | package CAM::PDF::Annot::Parsed; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use 5.010000; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 1 | our $VERSION = '0.10'; | |||||||||
| 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 | ▶ | use base qw( CAM::PDF::Annot ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 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 | 1 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 60 | 1 | my ($class, $file, $parser) = @_; | |||||||||
| 61 | 1 | my $self = $class->SUPER::new($file); | |||||||||
| 62 | 1 | $self->{_parser} = $parser; | |||||||||
| 63 | 1 | 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 | 1 | ▶ | sub getParsedAnnots { | ||||||||
|
Subroutine
getParsedAnnots: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||
| 76 | 1 | my ($self, $page) = @_; | |||||||||
| 77 | 1 | my $annots = []; | |||||||||
| 78 | 1 | for my $annot ( @{$self->getAnnotations($page)} ) { | |||||||||
| 79 | 2 | my $annotVal = $self->getValue( $annot ); | |||||||||
| 80 | 2 | ▶ | if ( exists $annotVal->{Contents} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 81 | 1 | ( my $parse_str = $self->getValue( $annotVal->{Contents} ) ) =~ s/\r\n/\n/g; | |||||||||
| 82 | 1 | ▶ | if ( my $parsed = $self->{_parser}->parse( $parse_str ) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 83 | 1 | push @$annots, $parsed; | |||||||||
| 84 | } | ||||||||||
| 85 | } | ||||||||||
| 86 | } | ||||||||||
| 87 | 1 | return $annots; | |||||||||
| 88 | } | ||||||||||
| 89 | |||||||||||
| 90 | 1 | 1; | |||||||||
| 91 | __END__ | ||||||||||