Hi All,
I have been having some problems getting the two modules to speak the same language...
My problem is that when I create a table in the PDFSimple class The PDF::Table creates pages without the headers and footers and inserts the table pages in-between the other pages...
Any help would be much appreciated... even worth a virtual beer or 2 :)
The code below is fully functional, you need to install PDF::API2::Simple and PDF::Table to make it work. If you run the .pl and look at the pdf that is created you will see what I mean with the table section not "attaching correctly" to the pdf.
Thanks in advance..
Craig
#!/usr/bin/perl -w
#
require 5.005;
use POSIX;
use strict;
use warnings;
use PDF::API2::Simple;
use PDF::Table;
my $page_num = 1;
my $pdf = PDF::API2::Simple->new(
file => '04_headers.pdf',
header => \&header,
footer => \&footer
);
my $pdftable = new PDF::Table;
$pdf->add_font('VerdanaBold');
$pdf->add_font('Verdana');
$pdf->add_page();
#####PAGE 1######################
my $strokecol = $pdf->strokecolor;
$pdf->next_line;
$pdf->next_line;
$pdf->set_font( 'VerdanaBold' );
$pdf->text('Hello World:',
x => $pdf->margin_left+20,
font_size => 10);
$pdf->next_line;
###############PAGE2#################################3
$pdf->add_page();
$pdf->next_line;
###############################
################################
my $data =[
["col1","col2","col3"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
["333","333","123"],
];
# build the table layout
$pdftable->table(
# required params
$pdf->pdf,
$pdf->current_page,
$data,
x => $pdf->margin_left,
w => $pdf->effective_width,
start_y => $pdf->margin_bottom + 500,
next_y => 750,
start_h => 500,
next_h => 720,
# some optional params
new_page_func => $pdf->add_page(),
header_props => {
font => $pdf->current_font,
font_size => 9,
font_color => '#000000',
bg_color => '#FF9046',
repeat => 1,
},
font => $pdf->current_font,
font_size => 9,
padding => 5,
padding_right => 10,
#background_color_odd => "gray",
#background_color_even => "lightblue",
#cell background color for even rows
);
################################################3
$pdf->add_page();
$pdf->save();
sub header {
my $strokecolor = $pdf->strokecolor;
my $y = $pdf->height - 20;
my $x = ($pdf->width / 2);
$pdf->stroke_color( '#555555' );
$pdf->next_line;
$pdf->set_font( 'VerdanaBold' );
$pdf->text( 'Header ',
x => $x,
y => $y,
font_size => 10,
align =>'center' );
$pdf->y( $pdf->y - 5 );
}
sub footer {
my $strokecol = $pdf->strokecolor;
$pdf->stroke_color( '#000000' );
$pdf->line( x => $pdf->margin_left,
y => 40,
to_x => $pdf->effective_width,
to_y => 40,
stroke => 'on',
fill => 'off',
width => 1 );
my $fillcolor = $pdf->fill_color;
my $font = $pdf->current_font;
$pdf->fill_color( '#000000' );
$pdf->set_font( 'VerdanaBold' );
$pdf->text( 'footer1',
x => $pdf->margin_left,
y => 30,
font_size => 9,
align => 'left' );
$pdf->next_line;
$pdf->set_font( 'Verdana' );
$pdf->text( ' footer 2',
x => $pdf->margin_left,
y => 20,
font_size => 8,
align => 'left' );
$pdf->set_font( 'VerdanaBold' );
$pdf->text( 'Page ' . $page_num++,
x => $pdf->effective_width,
y => 20,
align => 'right' );
$pdf->next_line;
$pdf->set_font( 'Verdana' );
$pdf->text( 'footer 3',
x => $pdf->margin_left,
y => 10,
font_size => 6,
align => 'left' );
$pdf->fill_color( $fillcolor );
$pdf->current_font( $font );
}