line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package TeX::AutoTeX::StampPDF; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# $Id: StampPDF.pm,v 1.9.2.7 2011/01/27 18:42:29 thorstens Exp $ |
5
|
|
|
|
|
|
|
# $Revision: 1.9.2.7 $ |
6
|
|
|
|
|
|
|
# $Source: /cvsroot/arxivlib/arXivLib/lib/TeX/AutoTeX/StampPDF.pm,v $ |
7
|
|
|
|
|
|
|
# |
8
|
|
|
|
|
|
|
# $Date: 2011/01/27 18:42:29 $ |
9
|
|
|
|
|
|
|
# $Author: thorstens $ |
10
|
|
|
|
|
|
|
# |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
24434
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
45
|
|
13
|
|
|
|
|
|
|
### use warnings; |
14
|
1
|
|
|
1
|
|
5
|
use Carp qw(cluck carp); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
124
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our ($VERSION) = '$Revision: 1.9.2.7 $' =~ m{ \$Revision: \s+ (\S+) }x; |
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
1
|
|
6
|
use parent qw(Exporter); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
19
|
|
|
|
|
|
|
our @EXPORT_OK = qw(stamp_pdf); |
20
|
1
|
|
|
1
|
|
1616
|
use CAM::PDF; |
|
1
|
|
|
|
|
35996
|
|
|
1
|
|
|
|
|
427
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub stamp_pdf { |
23
|
0
|
|
|
0
|
1
|
|
my ($file, $stampref) = @_; |
24
|
|
|
|
|
|
|
|
25
|
0
|
0
|
0
|
|
|
|
if (!(-r $file && ref $stampref eq 'ARRAY')) { |
26
|
|
|
|
|
|
|
#FIXME: pod2usage; |
27
|
0
|
|
|
|
|
|
throw TeX::AutoTeX::FatalException "must provide pdf file and stamp contents\n"; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# 6 * 72 - 1/2 * stringlength * 10 |
31
|
|
|
|
|
|
|
# (10 = approx average char width in 20pt Times-Roman) |
32
|
0
|
|
|
|
|
|
my $yoffset = 432 - 5 * length $stampref->[0]; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# minimal arXiv stamp used as a page overlay in grayscale |
35
|
0
|
|
|
|
|
|
my $pdfstamp = <<"EOSTAMP"; |
36
|
|
|
|
|
|
|
q |
37
|
|
|
|
|
|
|
0.5 G 0.5 g |
38
|
|
|
|
|
|
|
BT |
39
|
|
|
|
|
|
|
/arXivStAmP 20 Tf 0 1 -1 0 32 $yoffset Tm |
40
|
|
|
|
|
|
|
($stampref->[0])Tj |
41
|
|
|
|
|
|
|
ET |
42
|
|
|
|
|
|
|
Q |
43
|
|
|
|
|
|
|
EOSTAMP |
44
|
|
|
|
|
|
|
|
45
|
0
|
0
|
|
|
|
|
rename($file, "$file.bk") || throw TeX::AutoTeX::FatalException q{couldn't backup PDF file}; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
eval { |
48
|
0
|
|
0
|
|
|
|
my $doc = CAM::PDF->new("$file.bk") || cluck "$CAM::PDF::errstr\n"; |
49
|
0
|
0
|
|
|
|
|
if (!$doc->canModify()) { |
50
|
0
|
|
|
|
|
|
throw TeX::AutoTeX::FatalException "This PDF forbids modification\n"; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
$doc->appendPageContent(1, $pdfstamp); |
54
|
0
|
0
|
|
|
|
|
$doc->addFont(1, 'Times-Roman', 'arXivStAmP') || cluck "$CAM::PDF::errstr\n"; |
55
|
0
|
|
|
|
|
|
$doc->preserveOrder(); |
56
|
0
|
0
|
|
|
|
|
$doc->cleanoutput($file) || cluck "$CAM::PDF::errstr\n"; |
57
|
0
|
|
|
|
|
|
1; |
58
|
0
|
0
|
|
|
|
|
} or do { |
59
|
0
|
0
|
|
|
|
|
rename("$file.bk", $file) || carp 'woe is me, now that failed'; |
60
|
0
|
|
|
|
|
|
throw TeX::AutoTeX::FatalException "stamp operation did not complete\n"; |
61
|
|
|
|
|
|
|
}; |
62
|
0
|
0
|
|
|
|
|
if ($@) { |
63
|
0
|
0
|
|
|
|
|
rename("$file.bk", $file) || carp 'woe is me, now that failed'; |
64
|
0
|
|
|
|
|
|
throw TeX::AutoTeX::FatalException "an error occurred during stamp operation, reverted to original file\n"; |
65
|
|
|
|
|
|
|
} |
66
|
0
|
|
|
|
|
|
unlink "$file.bk"; |
67
|
0
|
|
|
|
|
|
return 0; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
1; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
__END__ |