File: 09-cgi-script.pl

package info (click to toggle)
libpdf-create-perl 1.46-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 652 kB
  • sloc: perl: 3,352; makefile: 8
file content (53 lines) | stat: -rw-r--r-- 1,431 bytes parent folder | download | duplicates (6)
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
49
50
51
52
53
#!/usr/bin/perl -w
#
# sample cgi-script to produce a PDF on the fly
#
# Markus Baertschi,  markus@markus.org
#

BEGIN { unshift @INC, "lib", "../lib" }
use strict;
use PDF::Create;
#use CGI;

#
# Write HTTP header with application/pdf as doc type
#
# If you want the PDF to open in an external application
# You should change this to
#   -type => 'application/x-pdf', -attachment => $pdfname
#
#print CGI::header( -type => 'application/pdf' );

#
# Start the pdf with '-' (stdout) as filename
#
my $pdf = PDF::Create->new( 'filename' => "-",
						   'Version'  => 1.2,
						   'PageMode' => 'UseOutlines',
						   'Author'   => 'Markus Baertschi',
						   'Title'    => 'Simple Test Document',
						 );

# create the document root
my $root = $pdf->new_page( 'MediaBox' => $pdf->get_page_size('A4') );

# Prepare 2 fonts
my $f1 = $pdf->font( 'Subtype'  => 'Type1',
					 'Encoding' => 'WinAnsiEncoding',
					 'BaseFont' => 'Helvetica'
				   );

# Add a page which inherits its attributes from $root
my $page = $root->new_page;

# Write some text to the page
$page->stringc( $f1, 40, 306, 700, 'PDF::Create' );
$page->stringc( $f1, 20, 306, 650, "version $PDF::Create::VERSION" );
$page->stringc( $f1, 20, 306, 600, 'Simple Test Document' );
$page->stringc( $f1, 20, 300, 300, 'Fabien Tassin' );
$page->stringc( $f1, 20, 300, 250, 'Markus Baertschi (markus@markus.org)' );

# Wrap up the PDF and close the file
$pdf->close;