-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathsample.pl
executable file
·64 lines (51 loc) · 1.91 KB
/
sample.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/perl -w
#
# sample PDF::Create usage
#
use strict;
use PDF::Create;
my $pdf = new PDF::Create('filename' => 'sample.pdf',
'Version' => 1.2,
'PageMode' => 'UseOutlines',
'Author' => 'John Doe',
'Title' => 'Sample Document',
);
my $root = $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 page which inherits its attributes from $root
my $page = $root->new_page;
# 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])');
# add another page
my $page2 = $root->new_page;
my $s2 = $toc->new_outline('Title' => 'Page 2', 'Destination' => $page2);
$s2->new_outline('Title' => 'GIF');
$s2->new_outline('Title' => 'JPEG');
# Draw a border around the page (A4 max is 595/842)
$page2->line(10, 10, 10, 832);
$page2->line(10, 10, 585, 10);
$page2->line(10, 832, 585, 832);
$page2->line(585, 10, 585, 832);
# Add a gif image
$page2->string($f1, 20, 50, 600, 'GIF Image:');
my $img1 = $pdf->image('pdf-logo.gif');
$page2->image('image'=>$img1, 'xscale'=>0.2,'yscale'=>0.2,'xpos'=>200,'ypos'=>600);
# Add a jpeg image
$page2->string($f1, 20, 50, 500, 'JPEG Image:');
my $img2 = $pdf->image('pdf-logo.jpg');
$page2->image('image'=>$img2, 'xscale'=>0.2,'yscale'=>0.2,'xpos'=>200,'ypos'=>500);
# Wrap up the PDF and close the file
$pdf->close;