6 our $VERSION = '0.9.3';
8 use List::Util qw(sum);
10 ############################################################
14 # Parameters are meta information about the PDF
16 # $pdf = PDF::Table->new();
18 ############################################################
24 my $class = ref($type) || $type;
26 bless ($self, $class);
30 ############################################################
32 # text_block - utility method to build multi-paragraph blocks of text
34 ############################################################
39 my $text_object = shift;
40 my $text = shift; # The text to be displayed
41 my %arg = @_; # Additional Arguments
43 my ( $align, $xpos, $ypos, $xbase, $ybase, $line_width, $wordspace, $endw , $width, $height) =
44 ( undef , undef, undef, undef , undef , undef , undef , undef , undef , undef );
45 my @line = (); # Temp data array with words on one line
46 my %width = (); # The width of every unique word in the givven text
48 # Try to provide backward compatibility
49 foreach my $key (keys %arg)
54 $arg{$newkey} = $arg{$key};
61 # Lets check mandatory parameters with no default values
63 $xbase = $arg{'x'} || -1;
64 $ybase = $arg{'y'} || -1;
65 $width = $arg{'w'} || -1;
66 $height = $arg{'h'} || -1;
67 unless( $xbase > 0 ){ print "Error: Left Edge of Block is NOT defined!\n"; return; }
68 unless( $ybase > 0 ){ print "Error: Base Line of Block is NOT defined!\n"; return; }
69 unless( $width > 0 ){ print "Error: Width of Block is NOT defined!\n"; return; }
70 unless( $height > 0 ){ print "Error: Height of Block is NOT defined!\n"; return; }
71 # Check if any text to display
72 unless( defined( $text) and length($text) > 0 )
74 print "Warning: No input text found. Trying to add dummy '-' and not to break everything.\n";
78 # Strip any <CR> and Split the text into paragraphs
80 my @paragraphs = split(/\n/, $text);
82 # Width between lines in pixels
83 my $line_space = defined $arg{'lead'} && $arg{'lead'} > 0 ? $arg{'lead'} : 12;
85 # Calculate width of all words
86 my $space_width = $text_object->advancewidth("\x20");
87 my @words = split(/\s+/, $text);
90 next if exists $width{$_};
91 $width{$_} = $text_object->advancewidth($_);
94 my @paragraph = split(' ', shift(@paragraphs));
96 my $first_paragraph = 1;
101 $ypos = $ybase + $line_space;
102 my $bottom_border = $ybase - $height;
103 # While we can add another line
104 while ( $ypos >= $bottom_border + $line_space )
106 # Is there any text to render ?
109 # Finish if nothing left
110 last unless scalar @paragraphs;
111 # Else take one line from the text
112 @paragraph = split(' ', shift( @paragraphs ) );
114 $ypos -= $arg{'parspace'} if $arg{'parspace'};
115 last unless $ypos >= $bottom_border;
117 $ypos -= $line_space;
120 # While there's room on the line, add another word
123 if( $first_line && exists $arg{'hang'} )
125 my $hang_width = $text_object->advancewidth($arg{'hang'});
127 $text_object->translate( $xpos, $ypos );
128 $text_object->text( $arg{'hang'} );
130 $xpos += $hang_width;
131 $line_width += $hang_width;
132 $arg{'indent'} += $hang_width if $first_paragraph;
134 elsif( $first_line && exists $arg{'flindent'} && $arg{'flindent'} > 0 )
136 $xpos += $arg{'flindent'};
137 $line_width += $arg{'flindent'};
139 elsif( $first_paragraph && exists $arg{'fpindent'} && $arg{'fpindent'} > 0 )
141 $xpos += $arg{'fpindent'};
142 $line_width += $arg{'fpindent'};
144 elsif (exists $arg{'indent'} && $arg{'indent'} > 0 )
146 $xpos += $arg{'indent'};
147 $line_width += $arg{'indent'};
150 # Lets take from paragraph as many words as we can put into $width - $indent;
151 while ( @paragraph and $text_object->advancewidth( join("\x20", @line)."\x20" . $paragraph[0]) +
152 $line_width < $width )
154 push(@line, shift(@paragraph));
156 $line_width += $text_object->advancewidth(join('', @line));
158 # calculate the space width
159 if( $arg{'align'} eq 'fulljustify' or ($arg{'align'} eq 'justify' and @paragraph))
161 @line = split(//,$line[0]) if (scalar(@line) == 1) ;
162 $wordspace = ($width - $line_width) / (scalar(@line) - 1);
167 $align=($arg{'align'} eq 'justify') ? 'left' : $arg{'align'};
168 $wordspace = $space_width;
170 $line_width += $wordspace * (scalar(@line) - 1);
172 if( $align eq 'justify')
174 foreach my $word (@line)
176 $text_object->translate( $xpos, $ypos );
177 $text_object->text( $word );
178 $xpos += ($width{$word} + $wordspace) if (@line);
184 # calculate the left hand position of the line
185 if( $align eq 'right' )
187 $xpos += $width - $line_width;
189 elsif( $align eq 'center' )
191 $xpos += ( $width / 2 ) - ( $line_width / 2 );
195 $text_object->translate( $xpos, $ypos );
196 $endw = $text_object->text( join("\x20", @line));
200 unshift(@paragraphs, join(' ',@paragraph)) if scalar(@paragraph);
201 return ($endw, $ypos, join("\n", @paragraphs))
205 ############################################################
206 # table - utility method to build multi-row, multicolumn tables
207 ############################################################
216 #=====================================
217 # Mandatory Arguments Section
218 #=====================================
219 unless($pdf and $page and $data)
221 print "Error: Mandatory parameter is missing pdf/page/data object!\n";
224 # Try to provide backward compatibility
225 foreach my $key (keys %arg)
228 if($newkey =~ s#^-##)
230 $arg{$newkey} = $arg{$key};
234 #TODO: Add code for header props compatibility and col_props comp....
236 my ( $xbase, $ybase, $width, $height ) = ( undef, undef, undef, undef );
237 # Could be 'int' or 'real' values
238 $xbase = $arg{'x' } || -1;
239 $ybase = $arg{'start_y'} || -1;
240 $width = $arg{'w' } || -1;
241 $height = $arg{'start_h'} || -1;
243 # Global geometry parameters are also mandatory.
244 unless( $xbase > 0 ){ print "Error: Left Edge of Table is NOT defined!\n"; return; }
245 unless( $ybase > 0 ){ print "Error: Base Line of Table is NOT defined!\n"; return; }
246 unless( $width > 0 ){ print "Error: Width of Table is NOT defined!\n"; return; }
247 unless( $height > 0 ){ print "Error: Height of Table is NOT defined!\n"; return; }
249 # Ensure default values for -next_y and -next_h
250 my $next_y = $arg{'next_y'} || $arg{'start_y'} || 0;
251 my $next_h = $arg{'next_h'} || $arg{'start_h'} || 0;
254 my $txt = $page->text;
255 # Set Default Properties
256 my $fnt_name = $arg{'font' } || $pdf->corefont('Times',-encode => 'utf8');
257 my $fnt_size = $arg{'font_size' } || 12;
258 my $max_word_len= $arg{'max_word_length' } || 20;
260 #=====================================
261 # Table Header Section
262 #=====================================
263 # Disable header row into the table
264 my $header_props = 0;
265 # Check if the user enabled it ?
266 if(defined $arg{'header_props'} and ref( $arg{'header_props'}) eq 'HASH')
268 # Transfer the reference to local variable
269 $header_props = $arg{'header_props'};
270 # Check other params and put defaults if needed
271 $header_props->{'repeat' } = $header_props->{'repeat' } || 0;
272 $header_props->{'font' } = $header_props->{'font' } || $fnt_name;
273 $header_props->{'font_color' } = $header_props->{'font_color' } || '#000066';
274 $header_props->{'font_size' } = $header_props->{'font_size' } || $fnt_size + 2;
275 $header_props->{'bg_color' } = $header_props->{'bg_color' } || '#FFFFAA';
277 my $header_row = undef;
278 #=====================================
279 # Other Parameters check
280 #=====================================
282 my $lead = $arg{'lead' } || $fnt_size;
283 my $pad_left = $arg{'padding_left' } || $arg{'padding'} || 0;
284 my $pad_right = $arg{'padding_right' } || $arg{'padding'} || 0;
285 my $pad_top = $arg{'padding_top' } || $arg{'padding'} || 0;
286 my $pad_bot = $arg{'padding_bottom' } || $arg{'padding'} || 0;
287 my $pad_w = $pad_left + $pad_right;
288 my $pad_h = $pad_top + $pad_bot ;
289 my $line_w = defined $arg{'border'} ? $arg{'border'} : 1 ;
291 my $background_color_even = $arg{'background_color_even' } || $arg{'background_color'} || undef;
292 my $background_color_odd = $arg{'background_color_odd' } || $arg{'background_color'} || undef;
293 my $font_color_even = $arg{'font_color_even' } || $arg{'font_color' } || 'black';
294 my $font_color_odd = $arg{'font_color_odd' } || $arg{'font_color' } || 'black';
295 my $border_color = $arg{'border_color' } || 'black';
297 my $min_row_h = $fnt_size + $pad_top + $pad_bot;
298 my $row_h = defined ($arg{'row_height'})
300 ($arg{'row_height'} > $min_row_h)
302 $arg{'row_height'} : $min_row_h;
306 my $cell_props = $arg{cell_props} || []; # per cell properties
307 my $row_cnt = ( ref $header_props and $header_props->{'repeat'} ) ? 1 : 0; # current row in user data
309 #If there is valid data array reference use it!
310 if(ref $data eq 'ARRAY')
312 # Copy the header row if header is enabled
313 @$header_row = $$data[0] if defined $header_props;
314 # Determine column widths based on content
316 # an arrayref whose values are a hashref holding
317 # the minimum and maximum width of that column
318 my $col_props = $arg{'column_props'} || [];
320 # An array ref of arrayrefs whose values are
321 # the actual widths of the column/row intersection
323 # An array ref with the widths of the header row
324 my $header_row_props = [];
326 # Scalars that hold sum of the maximum and minimum widths of all columns
327 my ( $max_col_w , $min_col_w ) = ( 0,0 );
328 my ( $row, $col_name, $col_fnt_size, $space_w );
330 # Hash that will hold the width of every word from input text
332 my $rows_counter = 0;
335 foreach $row ( @{$data} )
337 my $column_widths = []; #holds the width of each column
338 for( my $j = 0; $j < scalar(@$row) ; $j++ )
340 # look for font information for this column
341 $col_fnt_size = $col_props->[$j]->{'font_size'} || $fnt_size;
342 if( !$rows_counter and ref $header_props)
344 $txt->font( $header_props->{'font'}, $header_props->{'font_size'} );
346 elsif( $col_props->[$j]->{'font'} )
348 $txt->font( $col_props->[$j]->{'font'}, $col_fnt_size );
352 $txt->font( $fnt_name, $col_fnt_size );
355 # This should fix a bug with very long word like serial numbers etc.
356 # $myone is used because $1 gets out of scope in while condition
360 # This RegEx will split any word that is longer than {25} symbols
361 $row->[$j] =~ s#(\b\S{$max_word_len}?)(\S.*?\b)# $1 $2#;
362 $myone = 1 if( defined $2 );
365 $space_w = $txt->advancewidth( "\x20" );
366 $column_widths->[$j] = 0;
370 my @words = split( /\s+/, $row->[$j] );
374 unless( exists $word_w->{$_} )
375 { # Calculate the width of every word and add the space width to it
376 $word_w->{$_} = $txt->advancewidth( $_ ) + $space_w;
378 $column_widths->[$j] += $word_w->{$_};
379 $min_col_w = $word_w->{$_} if $word_w->{$_} > $min_col_w;
380 $max_col_w += $word_w->{$_};
382 $min_col_w += $pad_w;
383 $max_col_w += $pad_w;
384 $column_widths->[$j] += $pad_w;
386 # Keep a running total of the overall min and max widths
387 $col_props->[$j]->{min_w} = $col_props->[$j]->{min_w} || 0;
388 $col_props->[$j]->{max_w} = $col_props->[$j]->{max_w} || 0;
390 if( $min_col_w > $col_props->[$j]->{min_w} )
391 { # Calculated Minimum Column Width is more than user-defined
392 $col_props->[$j]->{min_w} = $min_col_w ;
394 if( $max_col_w > $col_props->[$j]->{max_w} )
395 { # Calculated Maximum Column Width is more than user-defined
396 $col_props->[$j]->{max_w} = $max_col_w ;
398 }#End of for(my $j....
399 $row_props->[$rows_counter] = $column_widths;
400 # Copy the calculated row properties of header row.
401 @$header_row_props = @$column_widths if(!$rows_counter and ref $header_props);
404 # Calc real column widths and expand table width if needed.
405 my $calc_column_widths;
406 ($calc_column_widths, $width) = $self->CalcColumnWidths( $col_props, $width );
407 my $num_cols = scalar @{ $calc_column_widths };
411 my ( $gfx , $gfx_bg , $background_color , $font_color, );
412 my ( $bot_marg, $table_top_y, $text_start , $record, $record_widths );
414 # Each iteration adds a new page as neccessary
415 while(scalar(@{$data}))
420 $table_top_y = $ybase;
421 $bot_marg = $table_top_y - $height;
425 if(ref $arg{'new_page_func'})
427 $page = &{$arg{'new_page_func'}};
434 $table_top_y = $next_y;
435 $bot_marg = $table_top_y - $next_h;
437 if( ref $header_props and $header_props->{'repeat'})
440 @$page_header = @$header_row;
442 @$hrp = @$header_row_props ;
443 # Then prepend it to master data array
444 unshift @$data ,@$page_header ;
445 unshift @$row_props ,$hrp ;
446 $first_row = 1; # Means YES
450 # Check for safety reasons
452 { # This warning should remain i think
453 # print "!!! Warning: !!! Incorrect Table Geometry! Setting bottom margin to end of sheet!\n";
457 $gfx_bg = $page->gfx;
459 $txt->font($fnt_name, $fnt_size);
461 $gfx->strokecolor($border_color);
462 $gfx->linewidth($line_w);
465 $cur_y = $table_top_y;
466 $gfx->move( $xbase , $cur_y );
467 $gfx->hline($xbase + $width );
469 # Each iteration adds a row to the current page until the page is full
470 # or there are no more rows to add
471 while(scalar(@{$data}) and $cur_y-$row_h > $bot_marg)
473 # Remove the next item from $data
474 $record = shift @{$data};
475 # Added to resolve infite loop bug with returned undef values
476 for(my $d = 0; $d < scalar(@{$record}) ; $d++)
478 $record->[$d] = '-' unless( defined $record->[$d]);
481 $record_widths = shift @$row_props;
484 # Choose colors for this row
485 $background_color = $rows_counter % 2 ? $background_color_even : $background_color_odd;
486 $font_color = $rows_counter % 2 ? $font_color_even : $font_color_odd;
488 if($first_row and ref $header_props)
490 $background_color = $header_props->{'bg_color'}
492 $text_start = $cur_y - $fnt_size - $pad_top;
494 my $leftovers = undef; # Reference to text that is returned from textblock()
495 my $do_leftovers = 0;
497 my ($colspan, @vertical_lines);
499 # Process every column from current row
500 for( my $j = 0; $j < scalar( @$record); $j++ )
502 next unless $col_props->[$j]->{max_w};
503 next unless $col_props->[$j]->{min_w};
504 $leftovers->[$j] = undef;
507 if( $first_row and ref $header_props )
509 $txt->fillcolor( $header_props->{'font_color'} );
511 elsif( $cell_props->[$row_cnt][$j]{font_color} )
513 $txt->fillcolor( $cell_props->[$row_cnt][$j]{font_color} );
515 elsif( $col_props->[$j]->{'font_color'} )
517 $txt->fillcolor( $col_props->[$j]->{'font_color'} );
521 $txt->fillcolor($font_color);
525 if( $first_row and ref $header_props )
527 $col_fnt_size = $header_props->{'font_size'};
529 elsif( $col_props->[$j]->{'font_size'} )
531 $col_fnt_size = $col_props->[$j]->{'font_size'};
535 $col_fnt_size = $fnt_size;
539 if( $first_row and ref $header_props )
541 $txt->font( $header_props->{'font'}, $header_props->{'font_size'});
543 elsif( $col_props->[$j]->{'font'} )
545 $txt->font( $col_props->[$j]->{'font'}, $col_fnt_size);
549 $txt->font( $fnt_name, $col_fnt_size);
551 #TODO: Implement Center text align
552 $col_props->[$j]->{justify} = $col_props->[$j]->{justify} || 'left';
555 if (!$first_row && $cell_props->[$row_cnt]->[$j]->{colspan}) {
556 $colspan = -1 == $cell_props->[$row_cnt]->[$j]->{colspan} ? $num_cols - $j : $cell_props->[$row_cnt]->[$j]->{colspan};
557 my $last_idx = $j + $colspan - 1;
558 $this_width = sum @{ $calc_column_widths }[$j..$last_idx];
561 $this_width = $calc_column_widths->[$j];
564 # If the content is wider than the specified width, we need to add the text as a text block
565 if($record->[$j] !~ m#(.\n.)# and $record_widths->[$j] and ($record_widths->[$j] < $this_width))
567 my $space = $pad_left;
568 if($col_props->[$j]->{justify} eq 'right')
570 $space = $this_width -($txt->advancewidth($record->[$j]) + $pad_right);
572 $txt->translate( $cur_x + $space, $text_start );
573 $txt->text( $record->[$j] );
575 # Otherwise just use the $page->text() method
578 my($width_of_last_line, $ypos_of_last_line, $left_over_text) = $self->text_block(
581 x => $cur_x + $pad_left,
583 w => $this_width - $pad_w,
584 h => $cur_y - $bot_marg - $pad_top - $pad_bot,
585 align => $col_props->[$j]->{justify},
588 # Desi - Removed $lead because of fixed incorrect ypos bug in text_block
589 my $this_row_h = $cur_y - ( $ypos_of_last_line - $pad_bot );
590 $row_h = $this_row_h if $this_row_h > $row_h;
591 if( $left_over_text )
593 $leftovers->[$j] = $left_over_text;
597 $cur_x += $calc_column_widths->[$j];
599 push @vertical_lines, (!$colspan || (1 >= $colspan)) ? 1 : 0;
600 $colspan-- if ($colspan);
604 unshift @$data, $leftovers;
605 unshift @$row_props, $record_widths;
609 # This has to be separately from the text loop
610 # because we do not know the final height of the cell until all text has been drawn
612 for(my $j =0;$j < scalar(@$record);$j++)
614 if ( $cell_props->[$row_cnt][$j]->{'background_color'} ||
615 $col_props->[$j]->{'background_color'} ||
618 $gfx_bg->rect( $cur_x, $cur_y-$row_h, $calc_column_widths->[$j], $row_h);
619 if ( $cell_props->[$row_cnt][$j]->{'background_color'} && !$first_row )
621 $gfx_bg->fillcolor($cell_props->[$row_cnt][$j]->{'background_color'});
623 elsif( $col_props->[$j]->{'background_color'} && !$first_row )
625 $gfx_bg->fillcolor($col_props->[$j]->{'background_color'});
629 $gfx_bg->fillcolor($background_color);
634 $cur_x += $calc_column_widths->[$j];
636 if ($line_w && $vertical_lines[$j] && ($j != (scalar(@{ $record }) - 1))) {
637 $gfx->move($cur_x, $cur_y);
638 $gfx->vline($cur_y - $row_h);
639 $gfx->fillcolor($border_color);
641 }#End of for(my $j....
645 $gfx->move( $xbase , $cur_y );
646 $gfx->hline( $xbase + $width );
648 $row_cnt++ unless ( $first_row );
650 }# End of while(scalar(@{$data}) and $cur_y-$row_h > $bot_marg)
652 # Draw vertical lines
654 $gfx->move($xbase, $table_top_y);
656 $gfx->move($xbase + sum(@{ $calc_column_widths }[0..$num_cols - 1]), $table_top_y);
658 $gfx->fillcolor($border_color);
662 }# End of while(scalar(@{$data}))
663 }# End of if(ref $data eq 'ARRAY')
665 return ($page,--$pg_cnt,$cur_y);
669 # calculate the column widths
673 my $col_props = shift;
674 my $avail_width = shift;
678 for(my $j = 0; $j < scalar( @$col_props); $j++)
680 $min_width += $col_props->[$j]->{min_w};
683 # I think this is the optimal variant when good view can be guaranateed
684 if($avail_width < $min_width)
686 # print "!!! Warning !!!\n Calculated Mininal width($min_width) > Table width($avail_width).\n",
687 # ' Expanding table width to:',int($min_width)+1,' but this could lead to unexpected results.',"\n",
688 # ' Possible solutions:',"\n",
689 # ' 0)Increase table width.',"\n",
690 # ' 1)Decrease font size.',"\n",
691 # ' 2)Choose a more narrow font.',"\n",
692 # ' 3)Decrease "max_word_length" parameter.',"\n",
693 # ' 4)Rotate page to landscape(if it is portrait).',"\n",
694 # ' 5)Use larger paper size.',"\n",
695 # '!!! --------- !!!',"\n";
696 $avail_width = int( $min_width) + 1;
701 # Calculate how much can be added to every column to fit the available width
702 $span = ($avail_width - $min_width) / scalar( @$col_props);
703 for(my $j = 0; $j < scalar(@$col_props); $j++ )
705 $calc_widths->[$j] = $col_props->[$j]->{min_w} + $span;
708 return ($calc_widths,$avail_width);
718 PDF::Table - A utility class for building table layouts in a PDF::API2 object.
725 my $pdftable = new PDF::Table;
726 my $pdf = new PDF::API2(-file => "table_of_lorem.pdf");
727 my $page = $pdf->page;
729 # some data to layout
731 ["1 Lorem ipsum dolor",
732 "Donec odio neque, faucibus vel",
733 "consequat quis, tincidunt vel, felis."],
734 ["Nulla euismod sem eget neque.",
740 $left_edge_of_table = 50;
741 # build the table layout
747 x => $left_edge_of_table,
753 # some optional params
756 background_color_odd => "gray",
757 background_color_even => "lightblue", #cell background color for even rows
760 # do other stuff with $pdf
766 For a complete working example or initial script look into distribution`s 'examples' folder.
771 This class is a utility for use with the PDF::API2 module from CPAN.
772 It can be used to display text data in a table layout within the PDF.
773 The text data must be in a 2d array (such as returned by a DBI statement handle fetchall_arrayref() call).
774 The PDF::Table will automatically add as many new pages as necessary to display all of the data.
775 Various layout properties, such as font, font size, and cell padding and background color can be specified for each column and/or for even/odd rows.
776 Also a (non)repeated header row with different layout properties can be specified.
778 See the METHODS section for complete documentation of every parameter.
786 Returns an instance of the class. There are no parameters.
790 =head2 table($pdf, $page_obj, $data, %opts)
794 The main method of this class.
795 Takes a PDF::API2 instance, a page instance, some data to build the table and formatting options.
796 The formatting options should be passed as named parameters.
797 This method will add more pages to the pdf instance as required based on the formatting options and the amount of data.
803 The return value is a 3 item list where
804 The first item is the PDF::API2::Page instance that the table ends on,
805 The second item is the count of pages that the table spans, and
806 The third item is the y position of the table bottom.
814 ($end_page, $pages_spanned, $table_bot_y) = $pdftable->table(
815 $pdf, # A PDF::API2 instance
816 $page_to_start_on, # A PDF::API2::Page instance created with $page_to_start_on = $pdf->page();
817 $data, # 2D arrayref of text strings
818 x => $left_edge_of_table, #X - coordinate of upper left corner
819 w => 570, # width of table.
820 start_y => $initial_y_position_on_first_page,
821 next_y => $initial_y_position_on_every_new_page,
822 start_h => $table_height_on_first_page,
823 next_h => $table_height_on_every_new_page,
824 #OPTIONAL PARAMS BELOW
825 max_word_length=> 20, # add a space after every 20th symbol in long words like serial numbers
826 padding => 5, # cell padding
827 padding_top => 10, # top cell padding, overides padding
828 padding_right => 10, # right cell padding, overides padding
829 padding_left => 10, # left cell padding, overides padding
830 padding_bottom => 10, # bottom padding, overides -padding
831 border => 1, # border width, default 1, use 0 for no border
832 border_color => 'red',# default black
833 font => $pdf->corefont("Helvetica", -encoding => "utf8"), # default font
835 font_color_odd => 'purple',
836 font_color_even=> 'black',
837 background_color_odd => 'gray', #cell background color for odd rows
838 background_color_even => 'lightblue', #cell background color for even rows
839 new_page_func => $code_ref, # see section TABLE SPANNING
840 header_props => $hdr_props, # see section HEADER ROW PROPERTIES
841 column_props => $col_props, # see section COLUMN PROPERTIES
842 cell_props => $row_props, # see section CELL PROPERTIES
849 =item HEADER ROW PROPERTIES
851 If the 'header_props' parameter is used, it should be a hashref.
852 It is your choice if it will be anonymous inline hash or predefined one.
853 Also as you can see there is no data variable for the content because the module asumes that the first table row will become the header row. It will copy this row and put it on every new page if 'repeat' param is set.
859 # This param could be a pdf core font or user specified TTF.
860 # See PDF::API2 FONT METHODS for more information
861 font => $pdf->corefont("Times", -encoding => "utf8"),
863 font_color => '#006666',
864 bg_color => 'yellow',
865 repeat => 1, # 1/0 eq On/Off if the header row should be repeated to every new page
870 =item COLUMN PROPERTIES
872 If the 'column_props' parameter is used, it should be an arrayref of hashrefs,
873 with one hashref for each column of the table. The columns are counted from left to right so the hash reference at $col_props[0] will hold properties for the first column from left to right.
874 If you DO NOT want to give properties for a column but to give for another just insert and empty hash reference into the array for the column that you want to skip. This will cause the counting to proceed as expected and the properties to be applyed at the right columns.
876 Each hashref can contain any of the keys shown below:
881 {},# This is an empty hash so the next one will hold the properties for the second row from left to right.
883 min_w => 100, # Minimum column width.
884 justify => 'right', # One of left|right ,
885 font => $pdf->corefont("Times", -encoding => "latin1"),
888 background_color => '#FFFF00',
895 If the 'min_w' parameter is used for 'col_props', have in mind that it can be overwritten
896 by the calculated minimum cell witdh if the userdefined value is less that calculated.
897 This is done for safety reasons.
898 In cases of a conflict between column formatting and odd/even row formatting,
899 the former will override the latter.
905 =item CELL PROPERTIES
907 If the 'cell_props' parameter is used, it should be an arrayref with arrays of hashrefs
908 (of the same dimension as the data array) with one hashref for each cell of the table.
909 Each hashref can contain any of keys shown here:
914 [ #This array is for the first row. If header_props is defined it will overwrite this settings.
916 background_color => '#AAAA00',
917 font_color => 'blue',
923 background_color => '#CCCC00',
924 font_color => 'blue',
927 background_color => '#CCCC00',
928 font_color => 'blue',
937 In case of a conflict between column, odd/even and cell formating, cell formating will overwrite the other two.
938 In case of a conflict between header row cell formating, header formating will win.
948 If used the parameter 'new_page_func' must be a function reference which when executed will create a new page and will return the object back to the module.
949 For example you can use it to put Page Title, Page Frame, Page Numbers and other staff that you need.
950 Also if you need some different type of paper size and orientation than the default A4-Portrait for example B2-Landscape you can use this function ref to set it up for you. For more info about creating pages refer to PDF::API2 PAGE METHODS Section.
951 Dont forget that your function must return a page object created with PDF::API2 page() method.
955 =head2 text_block( $txtobj, $string, x => $x, y => $y, w => $width, h => $height)
959 Utility method to create a block of text. The block may contain multiple paragraphs.
960 It is mainly used internaly but you can use it from outside for placing formated text anywhere on the sheet.
973 my $page = $pdf->page;
974 my $txt = $page->text;
980 ($width_of_last_line, $ypos_of_last_line, $left_over_text) = $pdftable->text_block(
983 #X,Y - coordinates of upper left corner
984 x => $left_edge_of_block,
985 y => $y_position_of_first_line,
986 w => $width_of_block,
987 h => $height_of_block,
989 lead => $font_size | $distance_between_lines,
990 align => "left|right|center|justify|fulljustify",
991 hang => $optional_hanging_indent,
992 Only one of the subsequent 3params can be given.
993 They override each other.-parspace is the weightest
994 parspace => $optional_vertical_space_before_first_paragraph,
995 flindent => $optional_indent_of_first_line,
996 fpindent => $optional_indent_of_first_paragraph,
998 indent => $optional_indent_of_text_to_every_non_first_line,
1010 ALL IMPROVEMENTS and BUGS Since Ver: 0.02
1018 =head1 COPYRIGHT AND LICENSE
1020 Copyright (C) 2006 by Daemmon Hughes, portions Copyright 2004 Stone
1021 Environmental Inc. (www.stone-env.com) All Rights Reserved.
1023 This library is free software; you can redistribute it and/or modify
1024 it under the same terms as Perl itself, either Perl version 5.8.4 or,
1025 at your option, any later version of Perl 5 you may have available.
1031 Much of the work on this module was sponsered by
1032 Stone Environmental Inc. (www.stone-env.com).
1034 The text_block() method is a slightly modified copy of the one from
1035 Rick Measham's PDF::API2 tutorial at
1036 http://pdfapi2.sourceforge.net/cgi-bin/view/Main/YourFirstDocument
1040 The development of this module is sponsored by SEEBURGER AG (www.seeburger.com)
1042 Thanks to my friends Krasimir Berov and Alex Kantchev for helpful tips and QA during development.