File: annotate.t

package info (click to toggle)
libpdf-api2-perl 2.047-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 20,228 kB
  • sloc: perl: 42,227; makefile: 11
file content (97 lines) | stat: -rw-r--r-- 2,476 bytes parent folder | download | duplicates (2)
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
use Test::More tests => 6;

use strict;
use warnings;

use PDF::API2;
use PDF::API2::Basic::PDF::Array;

my $pdf = PDF::API2->new(-compress => 0);
my $page = $pdf->page();

# 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});

# Link annotation

$pdf        = PDF::API2->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});

# URL annotation

$pdf        = PDF::API2->new();
$page       = $pdf->page();
$annotation = $page->annotation();

$annotation->url('http://perl.org');

$string = $pdf->to_string();
like($string,
    qr{/Annot /Subtype /Link /A << /S /URI /URI \(http://perl.org\) >>},
    q{URL Annotation});

# File annotation

$pdf        = PDF::API2->new();
$page       = $pdf->page();
$annotation = $page->annotation();

$annotation->file('test.pdf');

$string = $pdf->to_string();
like($string,
    qr{/Annot /Subtype /Link /A << /F \(test.pdf\) /S /Launch >>},
    q{File Annotation});

# PDF File annotation

$pdf        = PDF::API2->new();
$page       = $pdf->page();
$annotation = $page->annotation();

$annotation->pdf_file('test.pdf', 2);

$string = $pdf->to_string();
like($string,
    qr{/Annot /Subtype /Link /A << /D \[ 2 /XYZ null null null \] /F \(test.pdf\) /S /GoToR >>},
    q{File Annotation});

# [RT #118352] Crash if $page->annotation is called on a page with an
# existing Annots array stored in an indirect object

$pdf = PDF::API2->new();
$page = $pdf->page();

my $array = PDF::API2::Basic::PDF::Array->new();
$pdf->{'pdf'}->new_obj($array);

$page->{'Annots'} = $array;
$string = $pdf->to_string();

$pdf = PDF::API2->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});