1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
#!/usr/bin/perl
use strict;
use warnings;
use Test::More tests => 6;
use PDF::Builder;
use PDF::Builder::Basic::PDF::Array;
my $pdf = PDF::Builder->new('compress' => 'none');
my $page = $pdf->page();
# (1) Text annotation
my $annotation = $page->annotation();
$annotation->text('This is an annotation', 'rect' => [ 72, 144, 172, 244 ]);
my $string = $pdf->to_string();
like($string,
qr{/Annot /Subtype /Text /Border \[ 0 0 0 \] /Contents \(This is an annotation\) /Rect \[ 72 144 172 244 \]},
q{Text Annotation in a rectangle});
# (2) Link annotation
$pdf = PDF::Builder->new();
$page = $pdf->page();
$annotation = $page->annotation();
my $page2 = $pdf->page();
$annotation->link($page2);
$string = $pdf->to_string();
like($string,
qr{/Annot /Subtype /Link /A << /D \[ \d+ 0 R /XYZ null null null \] /S /GoTo >>},
q{Link Annotation});
# (3) URL annotation
$pdf = PDF::Builder->new();
$page = $pdf->page();
$annotation = $page->annotation();
$annotation->uri('http://perl.org');
$string = $pdf->to_string();
like($string,
qr{/Annot /Subtype /Link /A << /S /URI /URI \(http://perl.org\) >>},
q{URL Annotation});
# (4) File annotation
$pdf = PDF::Builder->new();
$page = $pdf->page();
$annotation = $page->annotation();
$annotation->launch('test.pdf');
$string = $pdf->to_string();
like($string,
qr{/Annot /Subtype /Link /A << /F \(test.pdf\) /S /Launch >>},
q{File Annotation});
# (5) PDF File annotation
$pdf = PDF::Builder->new();
$page = $pdf->page();
$annotation = $page->annotation();
$annotation->pdf('test.pdf', 2);
$string = $pdf->to_string();
like($string,
qr{/Annot /Subtype /Link /A << /D \[ 1 /XYZ null null null \] /F \(test.pdf\) /S /GoToR >>},
q{PDF File Annotation});
# [RT #118352] Crash if $page->annotation is called on a page with an
# existing Annots array stored in an indirect object
# (6) add to existing annotation
$pdf = PDF::Builder->new();
$page = $pdf->page();
my $array = PDF::Builder::Basic::PDF::Array->new();
$pdf->{'pdf'}->new_obj($array);
$page->{'Annots'} = $array;
$page->update();
$string = $pdf->to_string();
$pdf = PDF::Builder->from_string($string);
$page = $pdf->open_page(1);
$annotation = $page->annotation();
$annotation->text('This is an annotation', 'rect' => [ 72, 144, 172, 244 ]);
$string = $pdf->to_string();
like($string,
qr{/Annot /Subtype /Text /Border \[ 0 0 0 \] /Contents \(This is an annotation\) /Rect \[ 72 144 172 244 \]},
q{Add an annotation to an existing annotations array stored in an indirect object});
1;
|