Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl use strict; use warnings; use PDF::API2; use PDF::Table; use Data::Dumper; my $pdftable = new PDF::Table; my $pdf = new PDF::API2(-file => "test.pdf"); # save where you want th +e file to be $pdf->preferences( -thumbs => 1, ); my $page_num = 1; my @user_acc = ( "11111", "22222", "29989","23957", "20467", "39989"," +7723457", "013467", "288989", "345778", "33454", "23787", "19998","23957", "20460", "39980"," +7023457", "913467", "288869", "999876", "87497", "56467", "29344","23957", "12467", "37989"," +7726667", "013488", "238989", "119876", "20417", "23067", "89980","23957", "20117", "23989"," +4423457", "223467", "788989", "945876", "29457", "23467", "299895","239u7", "20467", "39h89", +"7o23457", "013467", "288989", "341778", "03454", "23784", "199989","23957", "20460", "39980", +"7023457", "913467", "218869", "999836", "87487", "56467", "900344","23953", "12467", "37989", +"7726667", "0134p8", "238989", "117876", "2B2417","23067", "899808","23957", "20919", "23989", +"4423457", "223467", "788789", "88888", ); # some data to layout my $some_data =[ ["Name", "Address", "City", "State", "Zip", "Phone", "Address 2", "Address 3", "Address 4", "Email", ], # content, 80 rows x 10 columns map { my $row = $_; [ map "$_", 1..10 ] } 1..80, ]; main_table($pdf, $some_data); $pdf->saveas(); ############## ###### ##### sub main_table { my $pdf = shift; my $data = shift; my $page = newpage(); # first page my $col_props = [ map{ #{}, # This is an empty hash so the next one will hold the propert +ies for the second row from left to right. { min_w => 5, # Minimum column width. justify => 'center', # One of left|right , font => $pdf->corefont("Times", -encoding => "latin1"), font_size => 5, font_color=> '#003366', background_color => '#000000', }, # etc. } 1..10, ]; # build the table layout $pdftable->table( # required params $pdf, $page, $data, x => 5, w => 780, start_y => 537, # 550 next_y => 537, start_h => 500, next_h => 500, # some optional params #max_word_length=> 20, # add a space after every 20th symbol in +long words like serial numbers padding => 1, # cell padding padding_top => 2, # top cell padding, overides padding padding_right => 2, # right cell padding, overides padding padding_left => 2, # left cell padding, overides padding padding_bottom => 2, # bottom padding, overides -padding border => 1, # border width, default 1, use 0 for no bo +rder border_color => '#000000', # default black font => $pdf->corefont("Helvetica", -encoding => "utf8") +, # default font #font => $pdf->corefont("Times", -encoding => "latin1"), background_color => '#FFFF00', font_size => 7, font_color_odd => '#000000', font_color_even=> '#000000', background_color_odd => '#e0e0e0', #gray cell background colo +r for odd rows - #d2d2d2 background_color_even => '#ffffff', #lightblue cell background + color for even rows new_page_func => \&newpage, # as defined above cell_render_hook => sub { # this is our newly introduced ca +llback function my ($page, $row, $col, $x, $y, $w, $h) = @_; #print Dumper $_[1]; #my @array=qw(0 1 2 3 4 5 6 7 8); #if ($col == 0) { # do nothing except for first column if (( $col == 0) && ($row >= 1) ) { # do nothing except f +or first column #$c++; my $url; my $c=-1; foreach my $user(@user_acc){ $c++; #$url = "http://www.mysite.com?test=$row&all_rows=$ +array[0]&useraccount=$user_acc[$col]"; } my $t = $row-1; $url = "http://www.mysite.com?test=$row&all_rows=$user +_acc[$t]"; print Dumper $url."x=".$x."y=".$y."w=".$w."h=".$h; + my $annot = $page->annotation(); $annot->url( $url, -rect => [$x, $y, $x+$w, $y+$h], -border => [1,1,1] ); } }, #header_props => { repeat => 1}, header_props => { font => $pdf->corefont("Helvetica", -encodi +ng => "uft8"), font_size => 7, font_color => '#ffffff', bg_color => '#003366', repeat => 1, }, #column_props => $col_props, column_props => [ map{{justify => 'center' }}1..10, ], ); } sub newpage { my $page = $pdf->page; $page->mediabox(792,612); header($page); footer($page); page_nr($page, $page_num++); return $page; } sub header { my $page = shift; # we need a page to place ourselves on my $head_data =[ ["User Information",], ["Data 1",], ["Auto Report System",] ]; $pdftable->table( # required params $pdf, $page, $head_data, x => 20, w => 750, start_y => 594, # top od doc on page - 594 next_y => 594, start_h => 100, next_h => 100, #OPTIONAL PARAMS BELOW #max_word_length=> 20, # add a space after every 20th symbo +l in long words like serial numbers padding => 3, # cell padding padding_top => 1, # top cell padding, overides padding #padding_right => 1, # right cell padding, overides paddi +ng #padding_left => 5, # left cell padding, overides paddin +g #padding_bottom => 5, # bottom padding, overides -padding border => 1, # border width, default 1, use 0 for + no border border_color => '#ffffff', # default black #font => $pdf->corefont("Helvetica", -encoding => " +utf8"), # default font #font_size => 10, #font_color_odd => 'black', #font_color_even=> 'black', #background_color_odd => "#ffffff", #background_color_even => "#003366", #cell background color f +or even rows #header_props => $hdr_props, column_props => [ { justify => 'center' } ], ); } sub footer { my $page = shift; # we need a page to place ourselves on my $footer_data =[ [ get_date() ] ]; $pdftable->table( # required params $pdf, $page, $footer_data, x => 20, w => 750, start_y => 30, # top od doc on page next_y => 30, start_h => 30, next_h => 30, #OPTIONAL PARAMS BELOW #max_word_length=> 20, # add a space after every 20th symbo +l in long words like serial numbers padding => 1, # cell padding border => 1, # border width, default 1, use 0 for + no border border_color => '#ffffff', # default black font => $pdf->corefont("Helvetica", -encoding => "u +tf8"), # default font font_size => 7, #header_props => $hdr_props, column_props => [ { justify => 'center' } ], ); } sub page_nr { my $page = shift; my $num = shift; $page->gfx->textlabel( # PDF::API2 method 760, 15, # x, y $pdf->corefont("Helvetica"), 8, # font, size "Page $num", # text -color => '#808080', -align => 'right', ); } sub get_date { my ($mon, $mday, $year) = (localtime)[4,3,5]; return sprintf '%02d-%02d-%04d', $mon+1, $mday, $year+1900; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: PDF::API2 Bug
by jethro (Monsignor) on May 29, 2009 at 18:04 UTC | |
by Anonymous Monk on May 29, 2009 at 18:38 UTC | |
by jethro (Monsignor) on May 29, 2009 at 21:51 UTC | |
by almut (Canon) on May 29, 2009 at 23:51 UTC | |
|
Re: PDF::API2 Bug
by almut (Canon) on May 29, 2009 at 23:53 UTC | |
by Anonymous Monk on Jun 01, 2009 at 13:34 UTC |