File Coverage

blib/lib/PDF/Imposition/Schema1x1.pm
Criterion Covered Total %
statement 42 43 97.6
branch 11 14 78.5
condition 1 3 33.3
subroutine 7 7 100.0
pod 1 1 100.0
total 62 68 91.1


line stmt bran cond sub pod time code
1             package PDF::Imposition::Schema1x1;
2 3     3   2034 use strict;
  3         5  
  3         95  
3 3     3   14 use warnings;
  3         4  
  3         102  
4              
5 3     3   13 use Types::Standard qw/Bool/;
  3         5  
  3         39  
6 3     3   1515 use namespace::clean;
  3         4  
  3         28  
7              
8              
9 3     3   645 use Moo;
  3         6  
  3         24  
10             with "PDF::Imposition::Schema";
11              
12              
13             =head1 NAME
14              
15             PDF::Imposition::Schema1x1 - 1:1 Imposition schema
16              
17             =head2 SYNOPSIS
18              
19             use PDF::Imposition::Schema1x1;
20             my $imposer = PDF::Imposition::Schema2up->new(
21             signature => "10-20",
22             file => "test.pdf",
23             output => "out.pdf",
24             cover => 1,
25             pages_per_sheet => 4,
26             );
27             $imposer->impose;
28              
29             The output pdf will be in C<$imposer->output>
30              
31             =head1 SCHEMA EXPLANATION
32              
33             This is a 1:1 imposition schema, meaning that apparently doesn't do anything.
34              
35             The purpose of this module is to do 2 things:
36              
37             =over 4
38              
39             =item Convert the PDF to version 1.4, if not already so.
40              
41             =item Handle the signature rounding and optimization
42              
43             This for example means that a pdf with 6 pages will end up with 8
44             pages (6 + 2 empty), and if you pass the C option with a true
45             value, you'll get the sixth page as page 8.
46              
47             Also you can get the computed value calling C and
48             the total output pages with C.
49              
50             =back
51              
52             If you don't need any of this, you don't have any reason to use this
53             module.
54              
55             =head2 cover
56              
57             This schema supports the cover option.
58              
59             =cut
60              
61             has cover => (is => 'rw', isa => Bool);
62              
63             sub _do_impose {
64 7     7   13 my $self = shift;
65 7         105 $self->out_pdf_obj->mediabox(
66             $self->orig_width,
67             $self->orig_height,
68             );
69 7         823 my $total_pages = $self->total_pages;
70 7         156 my $signature = $self->computed_signature;
71 7         28 my $max_page = $self->total_output_pages;
72 7         15 my $needed = $max_page - $total_pages;
73 7 50       22 die "negative number of needed pages, this is a bug" if $needed < 0;
74 7         23 my @sequence = (1 .. $total_pages);
75 7 100       20 if ($needed) {
76 6         8 my $last;
77 6 100       90 if ($self->cover) {
78 5         31 $last = pop @sequence;
79             }
80 6         23 while ($needed > 0) {
81 18         17 push @sequence, undef;
82 18         32 $needed--;
83             }
84 6 100       21 push @sequence, $last if $last;
85             }
86 7 50       19 die "Something went off" if @sequence != $max_page;
87 7         16 foreach my $pageno (@sequence) {
88 68         11199 my $page = $self->out_pdf_obj->page;
89 68         18972 my $gfx = $page->gfx;
90 68 100       7068 if (my $chunk = $self->get_imported_page($pageno)) {
91 50         1595581 $gfx->formimage($chunk, 0, 0);
92             }
93             }
94             }
95              
96             =head1 INTERNALS
97              
98             =head2 cropmarks_options
99              
100             Disable signature.
101              
102             =cut
103              
104             sub cropmarks_options {
105 2     2 1 4 my $self = shift;
106 2         19 my %options = (
107             top => 1,
108             bottom => 1,
109             inner => 1,
110             outer => 1,
111             # no shifting need
112             twoside => 0,
113             );
114 2 50 33     33 if ($self->signature and $self->pages_per_sheet > 1) {
115 0         0 $options{signature} = $self->computed_signature;
116             }
117             else {
118 2         31 $options{signature} = 0;
119             }
120              
121 2         42 return %options;
122             }
123              
124             1;