Hi Monks!
This code works fine but I am having a nightmare here trying to first; align the text inside the $head_data to the center of the page and also make this header text to show on every pdf page it generates. Also my $footer_data, which displays a date, I can't figure it out how to add this to all the pages. And also I am trying to find how I could add page numbers to the pdf pages generated.
If anyone worked on this type of stuff before it would be great to show me how I can get this done.
Thank you very much, and here is the code:

use strict; use PDF::API2; use PDF::API2::Annotation; use PDF::Table; my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(); $mon++; $year += 1900; my $s_date = sprintf '%02d-%02d-%04d', $mon, $mday, $year; my $page_num = 1; my $pdftable = new PDF::Table; my $pdf = new PDF::API2(-file => "pdf_test.pdf"); $pdf->preferences( -thumbs => 1, ); #$pdf->page($page_num); sub newpage { my $page = $pdf->page; $page->mediabox(792,612); my $txt = $page->text; #$page = $pdf->page(1); #my $pagenumber = $pdf->pages #$page->text; #$page = $pdf->pages; #$page->text( 'Page '.$page_num++, align =>'right' ); return $page; } my $page = newpage(); # some data to layout my $some_data =[ # same data as in your code... (not duplicated for brevity) ["Header 1", "Header 2", "Header 3", "Header 4", "Header 5" ], ["Content 1", "Content 2", "Content 3", "Content 4", "Content 5" ], ["Content 1", "Content 2", "Content 3", "Content 4", "Content 5" ], ["Content 1", "Content 2", "Content 3", "Content 4", "Content 5" ], ["Content 1", "Content 2", "Content 3", "Content 4", "Content 5" ], ["Content 1", "Content 2", "Content 3", "Content 4", "Content 5" ], ["Content 1", "Content 2", "Content 3", "Content 4", "Content 5" ], ["Content 1", "Content 2", "Content 3", "Content 4", "Content 5" ], ["Content 1", "Content 2", "Content 3", "Content 4", "Content 5" ], ["Content 1", "Content 2", "Content 3", "Content 4", "Content 5" ], ["Content 1", "Content 2", "Content 3", "Content 4", "Content 5" ], ["Content 1", "Content 2", "Content 3", "Content 4", "Content 5" ], ["Content 1", "Content 2", "Content 3", "Content 4", "Content 5" ], ["Content 1", "Content 2", "Content 3", "Content 4", "Content 5" ], ["Content 1", "Content 2", "Content 3", "Content 4", "Content 5" ], ["Content 1", "Content 2", "Content 3", "Content 4", "Content 5" ], ["Content 1", "Content 2", "Content 3", "Content 4", "Content 5" ], ["Content 1", "Content 2", "Content 3", "Content 4", "Content 5" ], ["Content 1", "Content 2", "Content 3", "Content 4", "Content 5" ], ["Content 1", "Content 2", "Content 3", "Content 4", "Content 5" ], ["Content 1", "Content 2", "Content 3", "Content 4", "Content 5" ], ["Content 1", "Content 2", "Content 3", "Content 4", "Content 5" ], ["Content 1", "Content 2", "Content 3", "Content 4", "Content 5" ], ["Content 1", "Content 2", "Content 3", "Content 4", "Content 5" ], ["Content 1", "Content 2", "Content 3", "Content 4", "Content 5" ], ["Content 1", "Content 2", "Content 3", "Content 4", "Content 5" ], ["Content 1", "Content 2", "Content 3", "Content 4", "Content 5" ], ["Content 1", "Content 2", "Content 3", "Content 4", "Content 5" ], ["Content 1", "Content 2", "Content 3", "Content 4", "Content 5" ], ["Content 1", "Content 2", "Content 3", "Content 4", "Content 5" ], ["Content 1", "Content 2", "Content 3", "Content 4", "Content 5" ], ["Content 1", "Content 2", "Content 3", "Content 4", "Content 5" ], ["Content 1", "Content 2", "Content 3", "Content 4", "Content 5" ], ["Content 1", "Content 2", "Content 3", "Content 4", "Content 5" ], ["Content 1", "Content 2", "Content 3", "Content 4", "Content 5" ], ]; ### Header Starts my $head_data =[ ["My Company Name",], ["List of Users",], ["Welcome User 1",] ]; $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 #justify => 'right', # One of left|right , #max_word_length=> 20, # add a space after every 20th symbol in + long words like serial numbers padding => 2, # cell padding #padding_top => 1, # top cell padding, overides padding padding_right => 10, # right cell padding, overides padding #padding_left => 5, # left cell padding, overides padding #padding_bottom => 5, # bottom padding, overides -padding border => 0, # border width, default 1, use 0 for no +border border_color => 'navy', # default black align => "center", #|right|center|justify|fulljustify", #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 => "#ffffff", #cell background color for e +ven rows #header_props => $hdr_props, #column_props => $col_props, ); ### End Header # build the table layout $pdftable->table( # required params $pdf, $page, $some_data, x => 70, w => 650, start_y => 527, # 550 next_y => 550, start_h => 500, next_h => 500, # some optional params padding => 5, padding_right => 10, background_color_odd => "gray", background_color_even => "lightblue", #cell background color for e +ven rows new_page_func => \&newpage, # as defined above cell_render_hook => sub { # this is our newly introduced callba +ck function my ($page, $row, $col, $x, $y, $w, $h) = @_; if ($col == 0) { # do nothing except for first column my $url = "http://www.anywhere.com?row=$row"; my $annot = $page->annotation(); $annot->url( $url, -rect => [$x, $y, $x+$w, $y+$h], -border => [1,1,1] ); } }, ), ##start footer #=code my $footer_data =[ [ " + + $s_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 justify => 'right', # One of left|right , #max_word_length=> 20, # add a space after every 20th symbol in + long words like serial numbers padding => 5, # cell padding border => 0, # border width, default 1, use 0 for no +border border_color => 'red', # default black font => $pdf->corefont("Helvetica", -encoding => "utf8" +), # default font font_size => 9, #header_props => $hdr_props, #column_props => $col_props, ); #=cut ## end footer # do other stuff with $pdf $pdf->saveas(); =code #patch PDF/Table.pm like this } # line 615 ### insert this if (ref $arg{cell_render_hook} eq 'CODE') { $arg{cell_render_hook}->( $page, $rows_counter, $j, $cur_x, $cur_y-$row_h, $calc_column_widths->[$j], $row_h ); } ### $cur_x += $calc_column_widths->[$j]; # orig. line 616 }#End of for(my $j.... # orig. line 617 =cut


In reply to Perl PDF format issue. by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.