Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks!

I am trying to make a PDF document using Perl, all its almost there( thanks to a sample code found here ), one of my issues is that I need to have a main table and inside of this table a few more tables. I am trying to pass/send these tables to the main table(inside). Its because the data coming from the database will be large and the main table needs to grow accordingly to the size of these tables been passed. Many pages will be generated. I think from the code I have here you will be able to see my nightmare. I am open for suggestions.
Thanks a lot for seeing this!
Here is the code:
#!/usr/bin/perl -w use strict; use PDF::API2; use PDF::Table; my $pdftable = new PDF::Table; my $pdf = new PDF::API2(-file => "pdf/table-1.pdf"); $pdf->preferences( -thumbs => 1, ); my $page_num = 1; my ($name_info, $city_info, $account_info, $location, $all_data); # this data will be from a db but here it is for testing only push @$name_info, ['John', 'Carter', 'Verify', 'First and Last', 'I +ncluded',], ['John', 'Carter', 'Verify', 'First and Last', 'I +ncluded',], ['John', 'Carter', 'Verify', 'First and Last', 'I +ncluded',], ['','','','','',], ; push @$city_info, ['Populated', 'Warm', 'Ocean', 'Flat', 'Winter',] +, ['','','','','',], ; push @$account_info, ['Paid Acccount', 'Debt', 'Amount', '250.00', 'To +tal',], ['Paid Acccount', 'Debt', 'Amount', '250.00', 'To +tal',], ['Paid Acccount', 'Debt', 'Amount', '250.00', 'To +tal',], ['Paid Acccount', 'Debt', 'Amount', '250.00', 'To +tal',], ['Paid Acccount', 'Debt', 'Amount', '250.00', 'To +tal',], ['','','','','',], ; push @$location, ['Residencial', 'Home', 'Private', 'Rent', 'Sale' +,], ['Residencial', 'Home', 'Private', 'Rent', 'Sale' +,], ['Residencial', 'Home', 'Private', 'Rent', 'Sale' +,], ['Residencial', 'Home', 'Private', 'Rent', 'Sale' +,], ['Residencial', 'Home', 'Private', 'Rent', 'Sale' +,], ['Residencial', 'Home', 'Private', 'Rent', 'Sale' +,], ['Residencial', 'Home', 'Private', 'Rent', 'Sale' +,], ['Residencial', 'Home', 'Private', 'Rent', 'Sale' +,], ['Residencial', 'Home', 'Private', 'Rent', 'Sale' +,], ['Residencial', 'Home', 'Private', 'Rent', 'Sale' +,], ['Residencial', 'Home', 'Private', 'Rent', 'Sale' +,], ['Residencial', 'Home', 'Private', 'Rent', 'Sale' +,], ['Residencial', 'Home', 'Private', 'Rent', 'Sale' +,], ['','','','','',], ; ############################ my $ref_name_info_header = [ "Name Information", ]; unshift @{ $name_info }, $ref_name_info_header; #name_info_table($pdf, \@{$name_info}); ############################ ############################ my $ref_city_info_header = [ "City Information", ]; unshift @{ $city_info }, $ref_city_info_header; #city_info_table($pdf, \@{$city_info}); ############################ ############################ my $ref_account_info_header = [ "Account", ]; unshift @{ $account_info }, $ref_account_info_header; #account_info_table($pdf, \@{$account_info}); ############################ ############################ my $ref_location_header = [ "Location", ]; unshift @{ $location }, $ref_location_header; #location_table($pdf, \@{$location}); ############################ ########## MAIN TABLE HEADER# my $ref_header = ["Header 1", "Header 2", "Header 3", "Header 4", "Header 5" ]; ############################ #unshift @{ $location }, $ref_header; # uncommment to test #main_table($pdf, \@{$location}); # uncommment to test # I know this is not possible this way, but thats what I am trying to +do. #push @$all_data, name_info_table, city_info_table, account_info_table +, location_table; unshift @{ $all_data }, $ref_header; main_table($pdf, \@{$all_data}); $pdf->saveas(); ########################## sub main_table { my $pdf = shift; my $data = shift; my $page = newpage(); # first page # build the table layout $pdftable->table( # required params $pdf, $page, $data, x => 70, w => 650, start_y => 550, next_y => 550, start_h => 500, next_h => 500, # some optional params padding => 5, padding_right => 10, border => 0, #background_color_odd => "gray", #background_color_even => "lightblue", new_page_func => \&newpage, # it brigs header to other pages header_props => { font => $pdf->corefont("Helvetica", -encodi +ng => "uft8"), font_size => 7, font_color => '#ffffff', bg_color => '#003366', repeat => 1, }, column_props => [ map{{justify => 'center' }}1..5, ], ), } ################ ################ sub newpage { my $page = $pdf->page; my $logo = "images/photo.png"; my $image = $pdf->image_png($logo, 181, 91); my $gfx = $page->gfx; $gfx->image($image, 5, 530); $page->mediabox(792,612); page_nr($page, $page_num++); return $page; } ################ ################ sub name_info_table { #my $page = shift; my $page = $pdf->page; my $pdf = shift; my $data = shift; $pdftable->table( # required params $pdf, $page, $data, x => 70, # move header to the right w => 650, start_y => 550, # top od doc on page - 594 next_y => 550, start_h => 500, next_h => 500, #OPTIONAL PARAMS BELOW padding => 1, # cell padding padding_top => 1, # top cell padding, overides padding border => 1, # border width, default 1, use 0 for + no border border_color => '#ffffff', # default black column_props => [ { justify => 'left' } ], ); } ################ ################ sub city_info_table { #my $page = shift; my $page = $pdf->page; my $pdf = shift; my $data = shift; $pdftable->table( # required params $pdf, $page, $data, x => 70, # move header to the right w => 650, start_y => 550, # top od doc on page - 594 next_y => 550, start_h => 500, next_h => 500, #OPTIONAL PARAMS BELOW padding => 1, # cell padding padding_top => 1, # top cell padding, overides padding border => 1, # border width, default 1, use 0 for + no border border_color => '#ffffff', # default black column_props => [ { justify => 'left' } ], ); } ################ ################ sub account_info_table { #my $page = shift; my $page = $pdf->page; my $pdf = shift; my $data = shift; $pdftable->table( # required params $pdf, $page, $data, x => 70, # move header to the right w => 650, start_y => 550, # top od doc on page - 594 next_y => 550, start_h => 500, next_h => 500, #OPTIONAL PARAMS BELOW padding => 1, # cell padding padding_top => 1, # top cell padding, overides padding border => 1, # border width, default 1, use 0 for + no border border_color => '#ffffff', # default black column_props => [ { justify => 'left' } ], ); } ################ ################ sub location_table { #my $page = shift; my $page = $pdf->page; my $pdf = shift; my $data = shift; $pdftable->table( # required params $pdf, $page, $data, x => 70, # move header to the right w => 650, start_y => 550, # top od doc on page - 594 next_y => 550, start_h => 500, next_h => 500, #OPTIONAL PARAMS BELOW padding => 1, # cell padding padding_top => 1, # top cell padding, overides padding border => 1, # border width, default 1, use 0 for + no border border_color => '#ffffff', # default black column_props => [ { justify => 'left' } ], ); } ################ ################ 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; } #################

Thanks again!