| 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 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | ### use warnings; | ||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use Carp qw(cluck carp); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 1 | our ($VERSION) = '$Revision: 1.9.2.7 $' =~ m{ \$Revision: \s+ (\S+) }x; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use parent qw(Exporter); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 1 | our @EXPORT_OK = qw(stamp_pdf); | |||||||||||||||||||||||||||
| 20 | 1 | ▶ | use CAM::PDF; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 0 | ▶ | sub stamp_pdf { | ||||||||||||||||||||||||||
|
Subroutine
stamp_pdf: not called CC=12 SCAR=50.5
Pod
documented
| |||||||||||||||||||||||||||||
| 23 | 0 | my ($file, $stampref) = @_; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 0 | ▶ | if (!(-r $file && ref $stampref eq 'ARRAY')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-r $file and ref $stampref eq "ARRAY"
MC/DC0%0/2
-r $file and ref $stampref eq "ARRAY"
-r $file
ref $stampref eq "ARRAY"
Truth table0%0/3
A and B
A= -r $fileB= 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 | ▶ | rename($file, "$file.bk") || throw TeX::AutoTeX::FatalException q{couldn't backup PDF file}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | eval { | ||||||||||||||||||||||||||||
| 48 | 0 | ▶ | my $doc = CAM::PDF->new("$file.bk") || cluck "$CAM::PDF::errstr\n"; | ||||||||||||||||||||||||||
|
Condition0%0/3
'CAM::PDF'->new("$file.bk") || cluck("$CAM::PDF::errstr\n")
MC/DC0%0/2
'CAM::PDF'->new("$file.bk") || cluck("$CAM::PDF::errstr\n")
'CAM::PDF'->new("$file.bk")
cluck("$CAM::PDF::errstr\n")
Truth table0%0/3
A || B
A= 'CAM::PDF'->new("$file.bk")B= cluck("$CAM::PDF::errstr\n")
| |||||||||||||||||||||||||||||
| 49 | 0 | ▶ | if (!$doc->canModify()) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 0 | throw TeX::AutoTeX::FatalException "This PDF forbids modification\n"; | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 0 | $doc->appendPageContent(1, $pdfstamp); | |||||||||||||||||||||||||||
| 54 | 0 | ▶ | $doc->addFont(1, 'Times-Roman', 'arXivStAmP') || cluck "$CAM::PDF::errstr\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 0 | $doc->preserveOrder(); | |||||||||||||||||||||||||||
| 56 | 0 | ▶ | $doc->cleanoutput($file) || cluck "$CAM::PDF::errstr\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | 0 | 1; | |||||||||||||||||||||||||||
| 58 | 0 | ▶ | } or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | rename("$file.bk", $file) || carp 'woe is me, now that failed'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 0 | throw TeX::AutoTeX::FatalException "stamp operation did not complete\n"; | |||||||||||||||||||||||||||
| 61 | }; | ||||||||||||||||||||||||||||
| 62 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | 0 | ▶ | rename("$file.bk", $file) || carp 'woe is me, now that failed'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | 1; | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | __END__ | ||||||||||||||||||||||||||||