-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathsample-cgi.pl
executable file
·49 lines (39 loc) · 1.34 KB
/
sample-cgi.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/perl -w
#
# sample PDF::Create usage for a Web CGI
#
# Inpired by alr with a CPAN annotation
#
use strict;
use PDF::Create;
use CGI;
# CGI Header designating the pdf data
print CGI::header( -type => 'application/x-pdf',
-attachment => 'sample.pdf' );
# Open pdf to stdout
my $pdf = new PDF::Create('filename' => '-', # STDOUT
'Version' => 1.2,
'PageMode' => 'UseOutlines',
'Author' => 'John Doe',
'Title' => 'Sample Document',
);
my $page = $pdf->new_page('MediaBox' => $pdf->get_page_size('a4'));
# Prepare 2 fonts
my $f1 = $pdf->font('Subtype' => 'Type1',
'Encoding' => 'WinAnsiEncoding',
'BaseFont' => 'Helvetica');
my $f2 = $pdf->font('Subtype' => 'Type1',
'Encoding' => 'WinAnsiEncoding',
'BaseFont' => 'Helvetica-Bold');
# Prepare a Table of Content
my $toc = $pdf->new_outline('Title' => 'Sample Document');
# Add a entry to the outline
$toc->new_outline('Title' => 'Page 1', 'Destination' => $page);
# Write some text to the page
$page->stringc($f2, 40, 306, 426, "PDF::Create");
$page->stringc($f1, 20, 306, 396, "version $PDF::Create::VERSION");
$page->stringc($f1, 20, 300, 300, 'Fabien Tassin');
$page->stringc($f1, 20, 300, 250, 'Markus Baertschi ([email protected])');
$page->stringc($f1, 20, 300, 200, 'sample-cgi.pl');
# Wrap up the PDF and close the file
$pdf->close;