example.pl untested

filter: Statementstmt 0.0% 0 / 38 Branchbran n/a Conditioncond 0.0% 0 / 2 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 4 Podpod n/a totaltotal 0.0% 0 / 44 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 use strict;
2 use PDF::API2;
3 use PDF::Sign qw(config :sign :ts);
4  
5 my $pdf = PDF::API2->new();
6 my $page = $pdf->page();
7 $page->size('A4');
8 my $content = $page->text();
9 $content->fill_color("#000");
10 my $font = $pdf->font('Helvetica');
11 $content->textlabel(297.5,500,$font,14,"Test Page",align=>"center");
12  
13 my $cert = "cert.pem";
14 my $key = "key.pem";
15 my $infile = "input.pdf";
16  
17 $pdf->saveas($infile);
18 $pdf = PDF::API2->open($infile);
19  
20 my $gen = system(
21 'openssl', 'req', '-x509', '-newkey', 'rsa:2048',
22 '-keyout', $key,
23 '-out', $cert,
24 '-days', '1',
25 '-nodes',
26 '-subj', '/C=IT/O=PDF-Sign-Test/CN=PDF-Sign Test Certificate',
27 '-config', 'openssl.cnf',
28 );
29  
30 config(
31 osslcmd => 'openssl',
32 x509_pem => $cert,
33 privkey_pem => $key,
34 tmpdir => '.',
35 );
36  
37 my $signature = eval {
38 cms_sign(
39 signer => $cert,
40 inkey => $key,
41 in => $infile,
42 )
43 };
44  
45 prepare_file($pdf, 1); # 0 = invisible, 1 = visible widget
46 my $signed = sign_file($pdf);
47  
48 # timestamp
49 my $pdf2 = PDF::API2->from_string($signed);
50 prepare_ts($pdf2);
51 my $timestamped = ts_file($pdf2);
52  
53 open(my $fh, '>:raw', 'output.pdf') or die $!;
54 print $fh $timestamped;
55 close $fh;
56 use Data::Dumper;
57 print Dumper(PDF::Sign::verify_signatures('output.pdf'));
58  
59  
60 __END__