File Coverage

blib/lib/PDF/API2/Basic/PDF/Page.pm
Criterion Covered Total %
statement 15 29 51.7
branch 0 4 0.0
condition n/a
subroutine 5 7 71.4
pod 2 2 100.0
total 22 42 52.3


line stmt bran cond sub pod time code
1             # Code in the PDF::API2::Basic::PDF namespace was originally copied from the
2             # Text::PDF distribution.
3             #
4             # Copyright Martin Hosken
5             #
6             # Martin Hosken's code may be used under the terms of the MIT license.
7             # Subsequent versions of the code have the same license as PDF::API2.
8              
9             package PDF::API2::Basic::PDF::Page;
10              
11 39     39   306 use base 'PDF::API2::Basic::PDF::Pages';
  39         125  
  39         19204  
12              
13 39     39   326 use strict;
  39         103  
  39         898  
14 39     39   212 use warnings;
  39         91  
  39         1559  
15              
16             our $VERSION = '2.043'; # VERSION
17              
18 39     39   274 use PDF::API2::Basic::PDF::Dict;
  39         104  
  39         762  
19 39     39   218 use PDF::API2::Basic::PDF::Utils;
  39         89  
  39         9842  
20              
21             =head1 NAME
22              
23             PDF::API2::Basic::PDF::Page - Low-level PDF page object
24              
25             =head1 DESCRIPTION
26              
27             Represents a page of output in PDF. It also keeps track of the content stream,
28             any resources (such as fonts) being switched, etc.
29              
30             Page inherits from Pages due to a number of shared methods. They are really
31             structurally quite different.
32              
33             =head1 INSTANCE VARIABLES
34              
35             A page has various working variables:
36              
37             =over
38              
39             =item curstrm
40              
41             The currently open stream
42              
43             =back
44              
45             =head1 METHODS
46              
47             =head2 PDF::API2::Basic::PDF::Page->new($pdf, $parent, $index)
48              
49             Creates a new page based on a pages object (perhaps the root object).
50              
51             The page is also added to the parent at this point, so pages are ordered in
52             a PDF document in the order in which they are created rather than in the order
53             they are closed.
54              
55             Only the essential elements in the page dictionary are created here, all others
56             are either optional or can be inherited.
57              
58             The optional index value indicates the index in the parent list that this page
59             should be inserted (so that new pages need not be appended)
60              
61             =cut
62              
63             sub new {
64 0     0 1   my ($class, $pdf, $parent, $index) = @_;
65 0           my $self = {};
66              
67 0 0         $class = ref($class) if ref($class);
68 0           $self = $class->SUPER::new($pdf, $parent);
69 0           $self->{'Type'} = PDFName('Page');
70 0           delete $self->{'Count'};
71 0           delete $self->{'Kids'};
72 0           $parent->add_page($self, $index);
73              
74 0           return $self;
75             }
76              
77             =head2 $p->ship_out($pdf)
78              
79             Ships the page out to the given output file context
80              
81             =cut
82              
83             sub ship_out {
84 0     0 1   my ($self, $pdf) = @_;
85              
86 0           $pdf->ship_out($self);
87 0 0         if (defined $self->{'Contents'}) {
88 0           $pdf->ship_out($self->{'Contents'}->elements());
89             }
90              
91 0           return $self;
92             }
93              
94             1;