- 论坛徽章:
- 0
|
回复 #1 chinatzbcn 的帖子
Using CPAN module PDF::Create
1. install PDF::Create
2. read perldoc PDF::Create
3. Sample code
use strict;
use PDF::Create;
my $pdf = new PDF::Create(
'filename' => 'myPerl.pdf',
'Version' => 1.2,
'PageMode' => 'UseOutlines',
'Author' => 'ulmer@chinaunix.net',
'Title' => 'Perl in ChinaUnix',
);
# set page size
my $root = $pdf->new_page('MediaBox' => [ 0, 0, 612, 792 ]);
# Add a page which inherits its attributes from $root
my $page = $root->new_page;
# Prepare 2 fonts
my $encode = 'WinAnsiEncoding';
my $font = 'Helvetica';
my $font_b = 'Helvetica-Bold';
# fonts obj
my $oF = $pdf->font('Subtype'=>'Type1','Encoding'=>$encode,'BaseFont'=>$font);
my $oFb = $pdf->font('Subtype'=>'Type1','Encoding'=>$encode,'BaseFont'=>$font_b);
# Prepare a Table of Content
my $toc = $pdf->new_outline('Title'=>'Perl', 'Destination'=>$page);
$toc->new_outline('Title' => 'Introduction');
my $s2 = $toc->new_outline('Title' => 'Variables', 'Status' => 'closed');
$s2->new_outline('Title' => 'Scalar');
$page->stringc($oFb, 40, 306, 426, "Perl - Introduction");
$page->stringc($oF, 20, 306, 396, "written by ulmer");
# Add another page
my $page2 = $root->new_page;
$page2->line(0, 0, 612, 792);
$page2->line(0, 792, 612, 0);
$toc->new_outline('Title' => 'Oprater');
$pdf->new_outline('Title' => 'Summary');
# Add something to the first page
$page->stringc($oF, 20, 306, 300, 'Perl makes life easy!');
# Add the missing PDF objects and a the footer then close the file
$pdf->close; |
|