line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Vector::QRCode::IntoPDF; |
2
|
2
|
|
|
2
|
|
21750
|
use 5.008005; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
70
|
|
3
|
2
|
|
|
2
|
|
11
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
72
|
|
4
|
2
|
|
|
2
|
|
20
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
55
|
|
5
|
2
|
|
|
2
|
|
1600
|
use PostScript::Convert; |
|
2
|
|
|
|
|
5247
|
|
|
2
|
|
|
|
|
110
|
|
6
|
2
|
|
|
2
|
|
2189
|
use PDF::API2; |
|
2
|
|
|
|
|
728461
|
|
|
2
|
|
|
|
|
118
|
|
7
|
2
|
|
|
2
|
|
2281
|
use Vector::QRCode::EPS; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use File::Temp 'tempdir'; |
9
|
|
|
|
|
|
|
use File::Spec; |
10
|
|
|
|
|
|
|
use Carp; |
11
|
|
|
|
|
|
|
use Class::Accessor::Lite ( |
12
|
|
|
|
|
|
|
new => 0, |
13
|
|
|
|
|
|
|
ro => [qw[pdf_file workdir]], |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = "0.02"; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub new { |
19
|
|
|
|
|
|
|
my ($class, %opts) = @_; |
20
|
|
|
|
|
|
|
croak 'pdf_file is required' unless $opts{pdf_file}; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
$opts{workdir} ||= tempdir(CLEANUP => 1); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
bless {%opts}, $class; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub pdf { |
28
|
|
|
|
|
|
|
my $self = shift; |
29
|
|
|
|
|
|
|
$self->{__pdf} ||= PDF::API2->open($self->pdf_file) or croak $!; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
$self->{__pdf}; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub imprint { |
35
|
|
|
|
|
|
|
my ($self, %opts) = @_; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
my %_opts; |
38
|
|
|
|
|
|
|
for my $key (qw/x y page/) { |
39
|
|
|
|
|
|
|
$_opts{$key} = delete $opts{$key} or croak "$key is required"; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
my $qr = $self->_qr_pdf(%opts) or croak "could not create qrcode"; |
43
|
|
|
|
|
|
|
my $page = $self->pdf->openpage($_opts{page}) or croak "illegal page"; |
44
|
|
|
|
|
|
|
my $gfx = $page->gfx; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
my $xobj = $self->pdf->importPageIntoForm($qr, 1); |
47
|
|
|
|
|
|
|
$gfx->formimage($xobj, $_opts{x}, $_opts{y}); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub save { |
51
|
|
|
|
|
|
|
my ($self, $path) = @_; |
52
|
|
|
|
|
|
|
$path ||= $self->pdf_file; |
53
|
|
|
|
|
|
|
$self->pdf->saveas($path); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub _qr_pdf { |
57
|
|
|
|
|
|
|
my ($self, %opts) = @_; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
my $qr = Vector::QRCode::EPS->generate(%opts); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
my $qr_data = $qr->get; |
62
|
|
|
|
|
|
|
my $qr_pdf = File::Spec->catfile($self->workdir, ($qr+0).'.pdf'); |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
psconvert(\$qr_data, filename => $qr_pdf, format => 'pdf'); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
PDF::API2->open($qr_pdf); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
1; |
70
|
|
|
|
|
|
|
__END__ |