PDF-Table-0.9.14/000755 000765 000024 00000000000 13203531116 013325 5ustar00desistaff000000 000000 PDF-Table-0.9.14/util/000755 000765 000024 00000000000 13203531115 014301 5ustar00desistaff000000 000000 PDF-Table-0.9.14/Changes000644 000765 000024 00000022041 13121420116 014613 0ustar00desistaff000000 000000 Change history for Perl extension PDF::Table. Version 0.9.13 Fixed issue #33 - Desislav Kamenov Version 0.9.12 - hotfix for failing tests - Desislav Kamenov Version 0.9.11 Changes by contributors on GitHub - Keith Carangelo, Mohammad S Anwar 3264342 Added cell_render_hook subroutine to create hyperlinks 0fb2e57 Fixed broken link to Rick Measham's tutorial. 8361ec3 Fixed new_page_func valid setting 38610ec Header alignment default should be column alignment e3ec184 Added parameter checking in the method table(). - Added unit test t/table.t script. a73e67f Proposed fix to the CPANTS error as below: - Added standard unit test for MANIFEST file (t/manifest.t). - Removed MYMETA.json, MYMETA.yml and Makefile (auto generated files) - Added entry "t/manifest.t" to the MANIFEST file. - Updated MANIFEST.SKIP file. Version 0.9.10 Changes by contributors on GitHub - azawawi, joenio 6fab323 Modernize hashbang #! to be more perlbrew friendly 58c36df Add relative link to Changes file efaf173 Simple installation/development commmands cfbcf48 More README.md simplification a7889bc Fix README.md 43c2182 Fix warning: Useless use of greediness modifier '?' in regex db4bc44 Fix #17, page parameter should be optional f93ed16 "utf8" pragma solves issue with characters rendered wrong e69524e fix script that test issue #15 5d5628f avoid warnind about use of greediness modifier Version 0.9.8/9 Added MANIFEST.SKIP and fixed a broken build with 0.9.8 Added some utility methods to new() Version 0.9.7 - for a detailed log and changed files visit GitHub Added a few initialisation methods to the help new() and later on accomodate static initialisation within table() textblock() Repackaged to fix Issue #16 Version 0.9.7 - for a detailed log and changed files visit GitHub Reviewed and updated README Huge POD rewrite Adding a small script that generates HTML from POD and applies CSS from CPAN. Useful for reviewing the POD before release. Added a test for POD validation Added an example file that can test GitHub Issues #8, #9, #10 GitHub [Issue #9] [Issue #10] Fixed cell_props applied to a different row when 'Repeat Headers' is enabled Introduced column_numbers variable to avoid using $record in a broader scope. Further improvement needed. Header row height is copied to each new page when 'Repeat Headers' is enabled Fixed messing up row height when repeat headers is enabled due to access by array index vs shift/unshift Fixed row height for rows with text blocks Headers_props variable has been wrongly initialised with 0 causing a copy of the first data row even when header props are not passed as parameter Added initialisation of header props justify param so that column and cell properties are not affecting the default value. Fixed an issue with messing up row properties when repeating the header row on each page. Examples have been formatted. One new example added (header.pl) for demonstrating how header row can be added to multiple pages. No need to export variables. Added one more test. Removed pad_w and pad_h local variable as useless Fixed typo causing a bug with row_height param. Added example file for row_height. To be used for writing a test. Added POD for row_height param Row counting should not be skipped if it is first row. Added one more test(duplicates existing) but only to have base. Extracted PDF::API2 Mock as a separate package. Created New test with the very basics. Create a new package that will hold predefined data for tests so it can be reused. Fixed a variable that masks earlier declaration. Fixed Issue #4 - Row height is calculated correctly depending on font size. Some variables are renamed to more meaningful. Row counting is done in a new way with single counter that is used for column and cell props retrieval. Row height is now calculated for each row based on maximum font size from all cells. Refactored some variable names and unified row counting during column size calculation phase. Fixed doc details in POD Cosmetic changes Decreased indent and reduced if body. For easier review, diff with whitespace changes disabled. Added github url in readme Version 0.9.6 ---------------------------- Fixed typo in POD. Closes #71816 Thanks to Gregor Herrmann Small code refactoring. Added patch for infinite loop fix. Closes #77376 Thanks to John Bazik Added patch for header justification. Closes #77566 Thanks to James Lance Added horizontal_borders, vertical_borders params to table(). Closes #79883 Thanks to Eric Johnson Version 0.9.5 - 18.Oct.2011 ---------------------------- MANIFEST was missing sample pdf file. Accidently left alternative code for infinite loop fix commented out. Fixed. Added a test for that. Version 0.9.4 - 17.Oct.2011 ---------------------------- Don't bump row count when row spans a page. Closes #67401. Fixed bug: don't call text_block if record width is exactly cell width. Fixed bug in text_block: bottom is (top - height), not (baseline - height). Example script typo fixed. Closes #55133. Don't set up strokes when border is 0. Apparently breaks Acrobat. Closes #40705 and #55137. Changed print warnings to carp. Closes #38007. Added center justification for columns and cells. Tests, too. Closes #37924. Fixed infinite loop caused by uninitialized $2. Thanks to Petri Kaurinkoski. Closes #34017. Fixed perl warning if $col_prop->{min_w} is undef. Thanks to Matthias Pitzl (NEPOS). Closes #30720. Fixed default header background color bug, closes #28542. Added mock PDF::API2 packages to test script and added tests. Improve column width calculations so wider content gets wider columns. Added column width test. Thanks to Barrie Slaymaker (RBS). Closes #26158. Version 0.9.3 - 27.12.2006 ---------------------------- Added backward compatibility and now again params with '-' front are supported. Both params with '-'and without are valid and can be even mixed together. I excuse for changing the interface before. Added cell_props parameter wich can define properties for a single cell as specified by user. Thanks for cell_props patch to Bodo Bauer. Removed Version requirement of Perl 5.8.7 and only version ot 5.6.0 is required. Thanks to Jonas Pasche for reporting it. Updated examples/sample1.pl file to try the capabilities of the module immidiately after download. Documentation Update. Fixed bug with interpreting \n as special char but not as newline. Thanks to Jonas Pasche for reporting it. (reminder: text with \n must be enclosed in double quotes i.e. "text\nnewline" ) Fixed documentation inacuracy for text_block(). It is called as $pdftable->text_block() of course. Thanks to Jonas Pasche for reporting it. Fixed bug with first_line overlaping with former paragraph last line. Thanks to Jonas Pasche for reporting it and contributing a patch. Version 0.9.2 - 02.Oct.2006 ---------------------------- Fixed bug with 'col_props->bg_color' overiding 'header_props->bg_color' Thanks to Giulio Di Giuliomaria Fixed some documentation inacuracys. Added some new documentation. 'column_props->width' parameter changed to 'min_w' Added example script to instantly test the module when downloaded. See 'examples' into the tar.gz archive. Version 0.9.1 - 18.Sep.2006 ---------------------------- Removed Debug Message "Created New Page" Fixed bug with not working header row bg_color parameter Thanks to Bodo Bauer for submiting the patch. Version 0.9 - 14.Sep.2006 ---------------------------- Fixed 'fontsize' bug at line 234 to font_size and parameter is working correctly Changed all parameters not to start with '-' So now '-start_h' becomes only 'start_h' Changed default font encoding form latin1 to UTF8 Added Default Values for next_h next_y parameters Added Minimum value check for x y start_h start_y Optimization for min row height calculations Added 'new_page_func parameter'. This is should be a reference to function which is called every time when a new page needs to be created so the table can span.See online manual for more info how to use it. Added Check if any text in sub text_block before spliting the parameter. Fixed bug with infinite loop when spanning to a new page. Splitting long words to parts because of breaking table cels Parameter in text_block() 'parspace' space before block start (paragraph). So the first line will start and height $ybase $parspace. So is every next paragraph into the block. Undocumented Parameter in text_block() 'indent' indent of every line Undocumented Parameter in text_block() 'flindent' indent of first line Undocumented Parameter in text_block() 'fpindent' indent of first paragraph The Above parameters are excluding each other in the following order: parspace,flindent,fpindent,indent The one that is found first and has valid value is beeing used Added Header Row support with repeat on every new page and different layout than the other rows Parameter 'w' for table is not optional any more (could change) Changed table width calculation and now module tries to use as much space as it is given but not more than it. Default values for many options Better source formatting Fixed incorect y position returned from text_block() Others that i dont remeber. PDF-Table-0.9.14/MANIFEST000644 000765 000024 00000000755 13203531116 014465 0ustar00desistaff000000 000000 Changes examples/header.pl examples/header_repeat_with_cell_props.pl examples/row_height.pl examples/sample1.pl examples/table_of_lorem.pdf lib/PDF/Table.pm Makefile.PL MANIFEST MANIFEST.SKIP README README.md t/Basics.t t/lib/PDFAPI2Mock.pm t/lib/TestData.pm t/PDF-Table.t t/pod.t t/manifest.t t/table.t util/pod2cpanhtml.pl META.yml Module YAML meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) PDF-Table-0.9.14/t/000755 000765 000024 00000000000 13203531115 013567 5ustar00desistaff000000 000000 PDF-Table-0.9.14/README000644 000765 000024 00000000074 13121140560 014204 0ustar00desistaff000000 000000 See README.md or visit https://github.com/kamenov/PDF-Table PDF-Table-0.9.14/README.md000644 000765 000024 00000002142 13121140560 014601 0ustar00desistaff000000 000000 # PDF::Table This module creates text blocks and tables into PDF documents using PDF::API2 Perl module. The official repository for PDF::Table module collaboration: https://github.com/kamenov/PDF-Table.git Any patches, pull requests, issues and feedback are more than welcome. ## Installation To install the module from CPAN, please type the following command: ```cpanm PDF::Table``` To test or add features to this module, please type the following command: ```cpanm .``` ## Changes To see a list of changes, please do one or more of the following: - Read the [Changes](Changes) file - Review commits history on GitHub - Make a diff from the tools menu at CPAN ## Contacts @deskata on Twitter - Use the issue tracker on GitHub - See http://search.cpan.org/~omega/ - See http://search.cpan.org/~jbazik/ ## License Copyright (C) 2006 by Daemmon Hughes Extended by Desislav Kamenov since version 0.02 This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.7 or, at your option, any later version of Perl 5 you may have available. PDF-Table-0.9.14/MANIFEST.SKIP000644 000765 000024 00000000357 13121140560 015226 0ustar00desistaff000000 000000 #Experimental/development/testing scripts and files ^experiment.*$ ^issue_scripts/.* #Backups .*\.old$ .*\.bak$ #Blib folder ^blib/* #Git folder ^\.git/* #Hidden files ^\..* #Auto-generated files ^MYMETA.json$ ^MYMETA.yml$ ^Makefile$ PDF-Table-0.9.14/examples/000755 000765 000024 00000000000 13203531115 015142 5ustar00desistaff000000 000000 PDF-Table-0.9.14/META.yml000644 000765 000024 00000001177 13203531116 014604 0ustar00desistaff000000 000000 --- abstract: 'A utility class for building table layouts in a PDF::API2 object.' author: - 'Desislav Kamenov ' build_requires: ExtUtils::MakeMaker: '0' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 7.24, CPAN::Meta::Converter version 2.143240' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: PDF-Table no_index: directory: - t - inc requires: {} resources: bugtracker: https://github.com/kamenov/PDF-Table/issues repository: https://github.com/kamenov/PDF-Table version: v0.9.14 PDF-Table-0.9.14/lib/000755 000765 000024 00000000000 13203531115 014072 5ustar00desistaff000000 000000 PDF-Table-0.9.14/Makefile.PL000644 000765 000024 00000001417 13121140560 015300 0ustar00desistaff000000 000000 use 5.006; use ExtUtils::MakeMaker; # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile that is written. WriteMakefile( NAME => 'PDF::Table', VERSION_FROM => 'lib/PDF/Table.pm', # finds $VERSION LICENSE => 'perl_5', PREREQ_PM => {}, # e.g., Module::Name => 1.1 ($] >= 5.005 ? ## Add these new keywords supported since 5.005 (ABSTRACT_FROM => 'lib/PDF/Table.pm', # retrieve abstract from module AUTHOR => 'Desislav Kamenov ') : ()), META_MERGE => { resources => { bugtracker => 'https://github.com/kamenov/PDF-Table/issues', repository => 'https://github.com/kamenov/PDF-Table', }, }, ); PDF-Table-0.9.14/META.json000644 000765 000024 00000002070 13203531116 014745 0ustar00desistaff000000 000000 { "abstract" : "A utility class for building table layouts in a PDF::API2 object.", "author" : [ "Desislav Kamenov " ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 7.24, CPAN::Meta::Converter version 2.143240", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "PDF-Table", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "runtime" : { "requires" : {} } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/kamenov/PDF-Table/issues" }, "repository" : { "url" : "https://github.com/kamenov/PDF-Table" } }, "version" : "v0.9.14" } PDF-Table-0.9.14/lib/PDF/000755 000765 000024 00000000000 13203531115 014503 5ustar00desistaff000000 000000 PDF-Table-0.9.14/lib/PDF/Table.pm000644 000765 000024 00000147000 13203530643 016077 0ustar00desistaff000000 000000 package PDF::Table; use 5.006; use strict; use warnings; use Carp; our $VERSION = '0.9.14'; print __PACKAGE__.' is version: '.$VERSION.$/ if($ENV{'PDF_TABLE_DEBUG'}); ############################################################ # # new - Constructor # # Parameters are meta information about the PDF # # $pdf = PDF::Table->new(); # ############################################################ sub new { my $type = shift(@_); my $class = ref($type) || $type; my $self = {}; bless ($self, $class); # Pass all the rest to init for validation and initialisation $self->_init(@_); return $self; } sub _init { my ($self, $pdf, $page, $data, %options ) = @_; # Check and set default values $self->set_defaults(); # Check and set mandatory params $self->set_pdf($pdf); $self->set_page($page); $self->set_data($data); $self->set_options(\%options); return; } sub set_defaults{ my $self = shift; $self->{'font_size'} = 12; } sub set_pdf{ my ($self, $pdf) = @_; $self->{'pdf'} = $pdf; } sub set_page{ my ($self, $page) = @_; if ( defined($page) && ref($page) ne 'PDF::API2::Page' ){ if( ref($self->{'pdf'}) eq 'PDF::API2' ){ $self->{'page'} = $self->{'pdf'}->page(); } else { carp 'Warning: Page must be a PDF::API2::Page object but it seems to be: '.ref($page).$/; carp 'Error: Cannot set page from passed PDF object either as it is invalid!'.$/; } return; } $self->{'page'} = $page; } sub set_data{ my ($self, $data) = @_; #TODO: implement } sub set_options{ my ($self, $options) = @_; #TODO: implement } ############################################################ # # text_block - utility method to build multi-paragraph blocks of text # ############################################################ sub text_block { my $self = shift; my $text_object = shift; my $text = shift; # The text to be displayed my %arg = @_; # Additional Arguments my ( $align, $xpos, $ypos, $xbase, $ybase, $line_width, $wordspace, $endw , $width, $height) = ( undef , undef, undef, undef , undef , undef , undef , undef , undef , undef ); my @line = (); # Temp data array with words on one line my %width = (); # The width of every unique word in the givven text # Try to provide backward compatibility foreach my $key (keys %arg) { my $newkey = $key; if($newkey =~ s#^-##) { $arg{$newkey} = $arg{$key}; delete $arg{$key}; } } ##### #--- # Lets check mandatory parameters with no default values #--- $xbase = $arg{'x'} || -1; $ybase = $arg{'y'} || -1; $width = $arg{'w'} || -1; $height = $arg{'h'} || -1; unless( $xbase > 0 ){ carp "Error: Left Edge of Block is NOT defined!\n"; return; } unless( $ybase > 0 ){ carp "Error: Base Line of Block is NOT defined!\n"; return; } unless( $width > 0 ){ carp "Error: Width of Block is NOT defined!\n"; return; } unless( $height > 0 ){ carp "Error: Height of Block is NOT defined!\n"; return; } # Check if any text to display unless( defined( $text) and length($text) > 0 ) { carp "Warning: No input text found. Trying to add dummy '-' and not to break everything.\n"; $text = '-'; } # Strip any and Split the text into paragraphs $text =~ s/\r//g; my @paragraphs = split(/\n/, $text); # Width between lines in pixels my $line_space = defined $arg{'lead'} && $arg{'lead'} > 0 ? $arg{'lead'} : 12; # Calculate width of all words my $space_width = $text_object->advancewidth("\x20"); my @words = split(/\s+/, $text); foreach (@words) { next if exists $width{$_}; $width{$_} = $text_object->advancewidth($_); } my @paragraph = split(' ', shift(@paragraphs)); my $first_line = 1; my $first_paragraph = 1; # Little Init $xpos = $xbase; $ypos = $ybase; $ypos = $ybase + $line_space; my $bottom_border = $ypos - $height; # While we can add another line while ( $ypos >= $bottom_border + $line_space ) { # Is there any text to render ? unless (@paragraph) { # Finish if nothing left last unless scalar @paragraphs; # Else take one line from the text @paragraph = split(' ', shift( @paragraphs ) ); $ypos -= $arg{'parspace'} if $arg{'parspace'}; last unless $ypos >= $bottom_border; } $ypos -= $line_space; $xpos = $xbase; # While there's room on the line, add another word @line = (); $line_width = 0; if( $first_line && exists $arg{'hang'} ) { my $hang_width = $text_object->advancewidth($arg{'hang'}); $text_object->translate( $xpos, $ypos ); $text_object->text( $arg{'hang'} ); $xpos += $hang_width; $line_width += $hang_width; $arg{'indent'} += $hang_width if $first_paragraph; } elsif( $first_line && exists $arg{'flindent'} && $arg{'flindent'} > 0 ) { $xpos += $arg{'flindent'}; $line_width += $arg{'flindent'}; } elsif( $first_paragraph && exists $arg{'fpindent'} && $arg{'fpindent'} > 0 ) { $xpos += $arg{'fpindent'}; $line_width += $arg{'fpindent'}; } elsif (exists $arg{'indent'} && $arg{'indent'} > 0 ) { $xpos += $arg{'indent'}; $line_width += $arg{'indent'}; } # Lets take from paragraph as many words as we can put into $width - $indent; while ( @paragraph and $text_object->advancewidth( join("\x20", @line)."\x20" . $paragraph[0]) + $line_width < $width ) { push(@line, shift(@paragraph)); } $line_width += $text_object->advancewidth(join('', @line)); # calculate the space width if( $arg{'align'} eq 'fulljustify' or ($arg{'align'} eq 'justify' and @paragraph)) { @line = split(//,$line[0]) if (scalar(@line) == 1) ; $wordspace = ($width - $line_width) / (scalar(@line) - 1); $align='justify'; } else { $align=($arg{'align'} eq 'justify') ? 'left' : $arg{'align'}; $wordspace = $space_width; } $line_width += $wordspace * (scalar(@line) - 1); if( $align eq 'justify') { foreach my $word (@line) { $text_object->translate( $xpos, $ypos ); $text_object->text( $word ); $xpos += ($width{$word} + $wordspace) if (@line); } $endw = $width; } else { # calculate the left hand position of the line if( $align eq 'right' ) { $xpos += $width - $line_width; } elsif( $align eq 'center' ) { $xpos += ( $width / 2 ) - ( $line_width / 2 ); } # render the line $text_object->translate( $xpos, $ypos ); $endw = $text_object->text( join("\x20", @line)); } $first_line = 0; }#End of while( unshift(@paragraphs, join(' ',@paragraph)) if scalar(@paragraph); return ($endw, $ypos, join("\n", @paragraphs)) } ################################################################ # table - utility method to build multi-row, multicolumn tables ################################################################ sub table { my $self = shift; my $pdf = shift; my $page = shift; my $data = shift; my %arg = @_; #===================================== # Mandatory Arguments Section #===================================== unless($pdf and $page and $data) { carp "Error: Mandatory parameter is missing pdf/page/data object!\n"; return; } # Validate mandatory argument data type croak "Error: Invalid pdf object received." unless (ref($pdf) eq 'PDF::API2'); croak "Error: Invalid page object received." unless (ref($page) eq 'PDF::API2::Page'); croak "Error: Invalid data received." unless ((ref($data) eq 'ARRAY') && scalar(@$data)); croak "Error: Missing required settings." unless (scalar(keys %arg)); # Validate settings key my %valid_settings_key = ( x => 1, w => 1, start_y => 1, start_h => 1, next_y => 1, next_h => 1, lead => 1, padding => 1, padding_right => 1, padding_left => 1, padding_top => 1, padding_bottom => 1, background_color => 1, background_color_odd => 1, background_color_even => 1, border => 1, border_color => 1, horizontal_borders => 1, vertical_borders => 1, font => 1, font_size => 1, font_color => 1, font_color_even => 1, font_color_odd => 1, background_color_odd => 1, background_color_even => 1, row_height => 1, new_page_func => 1, header_props => 1, column_props => 1, cell_props => 1, max_word_length => 1, cell_render_hook => 1, default_text => 1, ); foreach my $key (keys %arg) { # Provide backward compatibility $arg{$key} = delete $arg{"-$key"} if $key =~ s/^-//; croak "Error: Invalid setting key '$key' received." unless exists $valid_settings_key{$key}; } ###### #TODO: Add code for header props compatibility and col_props comp.... ###### my ( $xbase, $ybase, $width, $height ) = ( undef, undef, undef, undef ); # Could be 'int' or 'real' values $xbase = $arg{'x' } || -1; $ybase = $arg{'start_y'} || -1; $width = $arg{'w' } || -1; $height = $arg{'start_h'} || -1; # Global geometry parameters are also mandatory. unless( $xbase > 0 ){ carp "Error: Left Edge of Table is NOT defined!\n"; return; } unless( $ybase > 0 ){ carp "Error: Base Line of Table is NOT defined!\n"; return; } unless( $width > 0 ){ carp "Error: Width of Table is NOT defined!\n"; return; } unless( $height > 0 ){ carp "Error: Height of Table is NOT defined!\n"; return; } # Ensure default values for -next_y and -next_h my $next_y = $arg{'next_y'} || $arg{'start_y'} || 0; my $next_h = $arg{'next_h'} || $arg{'start_h'} || 0; # Create Text Object my $txt = $page->text; # Set Default Properties my $fnt_name = $arg{'font' } || $pdf->corefont('Times',-encode => 'utf8'); my $fnt_size = $arg{'font_size' } || 12; my $max_word_len= $arg{'max_word_length' } || 20; #===================================== # Table Header Section #===================================== # Disable header row into the table my $header_props = undef; # Check if the user enabled it ? if(defined $arg{'header_props'} and ref( $arg{'header_props'}) eq 'HASH') { # Transfer the reference to local variable $header_props = $arg{'header_props'}; # Check other params and put defaults if needed $header_props->{'repeat' } = $header_props->{'repeat' } || 0; $header_props->{'font' } = $header_props->{'font' } || $fnt_name; $header_props->{'font_color' } = $header_props->{'font_color' } || '#000066'; $header_props->{'font_size' } = $header_props->{'font_size' } || $fnt_size + 2; $header_props->{'bg_color' } = $header_props->{'bg_color' } || '#FFFFAA'; $header_props->{'justify' } = $header_props->{'justify' }; } my $header_row = undef; #===================================== # Other Parameters check #===================================== my $lead = $arg{'lead' } || $fnt_size; my $pad_left = $arg{'padding_left' } || $arg{'padding'} || 0; my $pad_right = $arg{'padding_right' } || $arg{'padding'} || 0; my $pad_top = $arg{'padding_top' } || $arg{'padding'} || 0; my $pad_bot = $arg{'padding_bottom'} || $arg{'padding'} || 0; my $default_text = $arg{'default_text' } // '-'; my $line_w = defined $arg{'border'} ? $arg{'border'} : 1 ; my $horiz_borders = defined $arg{'horizontal_borders'} ? $arg{'horizontal_borders'} : $line_w; my $vert_borders = defined $arg{'vertical_borders'} ? $arg{'vertical_borders'} : $line_w; my $background_color_even = $arg{'background_color_even' } || $arg{'background_color'} || undef; my $background_color_odd = $arg{'background_color_odd' } || $arg{'background_color'} || undef; my $font_color_even = $arg{'font_color_even' } || $arg{'font_color' } || 'black'; my $font_color_odd = $arg{'font_color_odd' } || $arg{'font_color' } || 'black'; my $border_color = $arg{'border_color' } || 'black'; my $min_row_h = $fnt_size + $pad_top + $pad_bot; my $row_h = defined ($arg{'row_height'}) && ($arg{'row_height'} > $min_row_h) ? $arg{'row_height'} : $min_row_h; my $pg_cnt = 1; my $cur_y = $ybase; my $cell_props = $arg{cell_props} || []; # per cell properties #If there is no valid data array reference warn and return! if(ref $data ne 'ARRAY') { carp "Passed table data is not an ARRAY reference. It's actually a ref to ".ref($data); return ($page,0,$cur_y); } # Copy the header row if header is enabled @$header_row = $$data[0] if defined $header_props; # Determine column widths based on content # an arrayref whose values are a hashref holding # the minimum and maximum width of that column my $col_props = $arg{'column_props'} || []; # An array ref of arrayrefs whose values are # the actual widths of the column/row intersection my $row_col_widths = []; # An array ref with the widths of the header row my $header_row_props = []; # Scalars that hold sum of the maximum and minimum widths of all columns my ( $max_col_w , $min_col_w ) = ( 0,0 ); my ( $row, $col_name, $col_fnt_size, $space_w ); my $word_widths = {}; my $rows_height = []; my $first_row = 1; for( my $row_idx = 0; $row_idx < scalar(@$data) ; $row_idx++ ) { my $column_widths = []; #holds the width of each column # Init the height for this row $rows_height->[$row_idx] = 0; for( my $column_idx = 0; $column_idx < scalar(@{$data->[$row_idx]}) ; $column_idx++ ) { # look for font information for this column my ($cell_font, $cell_font_size); if( !$row_idx and ref $header_props ) { $cell_font = $header_props->{'font'}; $cell_font_size = $header_props->{'font_size'}; } # Get the most specific value if none was already set from header_props $cell_font ||= $cell_props->[$row_idx][$column_idx]->{'font'} || $col_props->[$column_idx]->{'font'} || $fnt_name; $cell_font_size ||= $cell_props->[$row_idx][$column_idx]->{'font_size'} || $col_props->[$column_idx]->{'font_size'} || $fnt_size; # Set Font $txt->font( $cell_font, $cell_font_size ); # Set row height to biggest font size from row's cells if( $cell_font_size > $rows_height->[$row_idx] ) { $rows_height->[$row_idx] = $cell_font_size; } # This should fix a bug with very long words like serial numbers etc. if( $max_word_len > 0 ) { $data->[$row_idx][$column_idx] =~ s#(\S{$max_word_len})(?=\S)#$1 #g; } # Init cell size limits $space_w = $txt->advancewidth( "\x20" ); $column_widths->[$column_idx] = 0; $max_col_w = 0; $min_col_w = 0; my @words = split( /\s+/, $data->[$row_idx][$column_idx] ); foreach( @words ) { unless( exists $word_widths->{$_} ) { # Calculate the width of every word and add the space width to it $word_widths->{$_} = $txt->advancewidth( $_ ) + $space_w; } $column_widths->[$column_idx] += $word_widths->{$_}; $min_col_w = $word_widths->{$_} if( $word_widths->{$_} > $min_col_w ); $max_col_w += $word_widths->{$_}; } $min_col_w += $pad_left + $pad_right; $max_col_w += $pad_left + $pad_right; $column_widths->[$column_idx] += $pad_left + $pad_right; # Keep a running total of the overall min and max widths $col_props->[$column_idx]->{'min_w'} ||= 0; $col_props->[$column_idx]->{'max_w'} ||= 0; if( $min_col_w > $col_props->[$column_idx]->{'min_w'} ) { # Calculated Minimum Column Width is more than user-defined $col_props->[$column_idx]->{'min_w'} = $min_col_w ; } if( $max_col_w > $col_props->[$column_idx]->{'max_w'} ) { # Calculated Maximum Column Width is more than user-defined $col_props->[$column_idx]->{'max_w'} = $max_col_w ; } }#End of for(my $column_idx.... $row_col_widths->[$row_idx] = $column_widths; # Copy the calculated row properties of header row. @$header_row_props = @$column_widths if(!$row_idx and ref $header_props); } # Calc real column widths and expand table width if needed. my $calc_column_widths; ($calc_column_widths, $width) = CalcColumnWidths( $col_props, $width ); # Lets draw what we have! my $row_index = 0; # Store header row height for later use if headers have to be repeated my $header_row_height = $rows_height->[0]; my ( $gfx, $gfx_bg, $background_color, $font_color, $bot_marg, $table_top_y, $text_start); # Each iteration adds a new page as neccessary while(scalar(@{$data})) { my ($page_header, $columns_number); if($pg_cnt == 1) { $table_top_y = $ybase; $bot_marg = $table_top_y - $height; } else { if(ref $arg{'new_page_func'}) { $page = &{$arg{'new_page_func'}}; } else { $page = $pdf->page; } $table_top_y = $next_y; $bot_marg = $table_top_y - $next_h; if( ref $header_props and $header_props->{'repeat'}) { # Copy Header Data @$page_header = @$header_row; my $hrp ; @$hrp = @$header_row_props ; # Then prepend it to master data array unshift @$data, @$page_header; unshift @$row_col_widths, $hrp; unshift @$rows_height, $header_row_height; $first_row = 1; # Means YES $row_index--; # Rollback the row_index because a new header row has been added } } # Check for safety reasons if( $bot_marg < 0 ) { # This warning should remain i think carp "!!! Warning: !!! Incorrect Table Geometry! Setting bottom margin to end of sheet!\n"; $bot_marg = 0; } $gfx_bg = $page->gfx; $txt = $page->text; $txt->font($fnt_name, $fnt_size); $cur_y = $table_top_y; if ($line_w) { $gfx = $page->gfx; $gfx->strokecolor($border_color); $gfx->linewidth($line_w); # Draw the top line if ($horiz_borders) { $gfx->move( $xbase , $cur_y ); $gfx->hline($xbase + $width ); } } else { $gfx = undef; } # Each iteration adds a row to the current page until the page is full # or there are no more rows to add # Row_Loop while(scalar(@{$data}) and $cur_y-$row_h > $bot_marg) { # Remove the next item from $data my $record = shift @{$data}; # Get columns number to know later how many vertical lines to draw # TODO: get the max number of columns per page as currently last row's columns overrides $columns_number = scalar(@$record); # Get the next set of row related settings # Row Height my $pre_calculated_row_height = shift @$rows_height; # Row cell widths my $record_widths = shift @$row_col_widths; # Row coloumn props - TODO in another commit # Row cell props - TODO in another commit # Choose colors for this row $background_color = $row_index % 2 ? $background_color_even : $background_color_odd; $font_color = $row_index % 2 ? $font_color_even : $font_color_odd; #Determine current row height my $current_row_height = $pad_top + $pre_calculated_row_height + $pad_bot; # $row_h is the calculated global user requested row height. # It will be honored, only if it has bigger value than the calculated one. # TODO: It's questionable if padding should be inclided in this calculation or not if($current_row_height < $row_h){ $current_row_height = $row_h; } # Define the font y base position for this line. $text_start = $cur_y - ($current_row_height - $pad_bot); my $cur_x = $xbase; my $leftovers = undef; # Reference to text that is returned from textblock() my $do_leftovers = 0; # Process every cell(column) from current row for( my $column_idx = 0; $column_idx < scalar( @$record); $column_idx++ ) { next unless $col_props->[$column_idx]->{'max_w'}; next unless $col_props->[$column_idx]->{'min_w'}; $leftovers->[$column_idx] = undef; # look for font information for this cell my ($cell_font, $cell_font_size, $cell_font_color, $justify); if( $first_row and ref $header_props) { $cell_font = $header_props->{'font'}; $cell_font_size = $header_props->{'font_size'}; $cell_font_color = $header_props->{'font_color'}; $justify = $header_props->{'justify'}; } # Get the most specific value if none was already set from header_props $cell_font ||= $cell_props->[$row_index][$column_idx]->{'font'} || $col_props->[$column_idx]->{'font'} || $fnt_name; $cell_font_size ||= $cell_props->[$row_index][$column_idx]->{'font_size'} || $col_props->[$column_idx]->{'font_size'} || $fnt_size; $cell_font_color ||= $cell_props->[$row_index][$column_idx]->{'font_color'} || $col_props->[$column_idx]->{'font_color'} || $font_color; $justify ||= $cell_props->[$row_index][$column_idx]->{'justify'} || $col_props->[$column_idx]->{'justify'} || $arg{'justify'} || 'left'; # Init cell font object $txt->font( $cell_font, $cell_font_size ); $txt->fillcolor($cell_font_color); # Added to resolve infite loop bug with returned undef values $record->[$column_idx] //= $cell_props->[$row_index][$column_idx]->{'default_text'} // $col_props->[$column_idx]->{'default_text'} // $default_text; # If the content is wider than the specified width, we need to add the text as a text block if( $record->[$column_idx] !~ m/(.\n.)/ and $record_widths->[$column_idx] and $record_widths->[$column_idx] <= $calc_column_widths->[$column_idx] ){ my $space = $pad_left; if ($justify eq 'right') { $space = $calc_column_widths->[$column_idx] -($txt->advancewidth($record->[$column_idx]) + $pad_right); } elsif ($justify eq 'center') { $space = ($calc_column_widths->[$column_idx] - $txt->advancewidth($record->[$column_idx])) / 2; } $txt->translate( $cur_x + $space, $text_start ); $txt->text( $record->[$column_idx] ); } # Otherwise just use the $page->text() method else { my ($width_of_last_line, $ypos_of_last_line, $left_over_text) = $self->text_block( $txt, $record->[$column_idx], x => $cur_x + $pad_left, y => $text_start, w => $calc_column_widths->[$column_idx] - $pad_left - $pad_right, h => $cur_y - $bot_marg - $pad_top - $pad_bot, align => $justify, lead => $lead ); # Desi - Removed $lead because of fixed incorrect ypos bug in text_block my $current_cell_height = $cur_y - $ypos_of_last_line + $pad_bot; if( $current_cell_height > $current_row_height ) { $current_row_height = $current_cell_height; } if( $left_over_text ) { $leftovers->[$column_idx] = $left_over_text; $do_leftovers = 1; } } # Hook to pass coordinates back - http://www.perlmonks.org/?node_id=754777 if (ref $arg{cell_render_hook} eq 'CODE') { $arg{cell_render_hook}->( $page, $first_row, $row_index, $column_idx, $cur_x, $cur_y-$row_h, $calc_column_widths->[$column_idx], $row_h ); } $cur_x += $calc_column_widths->[$column_idx]; } if( $do_leftovers ) { unshift @$data, $leftovers; unshift @$row_col_widths, $record_widths; unshift @$rows_height, $pre_calculated_row_height; } # Draw cell bgcolor # This has to be separately from the text loop # because we do not know the final height of the cell until all text has been drawn $cur_x = $xbase; for(my $column_idx = 0 ; $column_idx < scalar(@$record) ; $column_idx++) { my $cell_bg_color; if( $first_row and ref $header_props) { #Compatibility Consistency with other props $cell_bg_color = $header_props->{'bg_color'} || $header_props->{'background_color'}; } # Get the most specific value if none was already set from header_props $cell_bg_color ||= $cell_props->[$row_index][$column_idx]->{'background_color'} || $col_props->[$column_idx]->{'background_color'} || $background_color; if ($cell_bg_color) { $gfx_bg->rect( $cur_x, $cur_y-$current_row_height, $calc_column_widths->[$column_idx], $current_row_height); $gfx_bg->fillcolor($cell_bg_color); $gfx_bg->fill(); } $cur_x += $calc_column_widths->[$column_idx]; }#End of for(my $column_idx.... $cur_y -= $current_row_height; if ($gfx && $horiz_borders) { $gfx->move( $xbase , $cur_y ); $gfx->hline( $xbase + $width ); } $row_index++ unless ( $do_leftovers ); $first_row = 0; }# End of Row_Loop if ($gfx) { # Draw vertical lines if ($vert_borders) { $gfx->move( $xbase, $table_top_y); $gfx->vline( $cur_y ); my $cur_x = $xbase; for( my $j = 0; $j < $columns_number; $j++ ) { $cur_x += $calc_column_widths->[$j]; $gfx->move( $cur_x, $table_top_y ); $gfx->vline( $cur_y ); } } # ACTUALLY draw all the lines $gfx->fillcolor( $border_color); $gfx->stroke; } $pg_cnt++; }# End of while(scalar(@{$data})) return ($page,--$pg_cnt,$cur_y); } # calculate the column widths sub CalcColumnWidths { my $col_props = shift; my $avail_width = shift; my $min_width = 0; my $calc_widths ; for(my $j = 0; $j < scalar( @$col_props); $j++) { $min_width += $col_props->[$j]->{min_w} || 0; } # I think this is the optimal variant when good view can be guaranateed if($avail_width < $min_width) { carp "!!! Warning !!!\n Calculated Mininal width($min_width) > Table width($avail_width).\n", ' Expanding table width to:',int($min_width)+1,' but this could lead to unexpected results.',"\n", ' Possible solutions:',"\n", ' 0)Increase table width.',"\n", ' 1)Decrease font size.',"\n", ' 2)Choose a more narrow font.',"\n", ' 3)Decrease "max_word_length" parameter.',"\n", ' 4)Rotate page to landscape(if it is portrait).',"\n", ' 5)Use larger paper size.',"\n", '!!! --------- !!!',"\n"; $avail_width = int( $min_width) + 1; } # Calculate how much can be added to every column to fit the available width. for(my $j = 0; $j < scalar(@$col_props); $j++ ) { $calc_widths->[$j] = $col_props->[$j]->{min_w} || 0;; } # Allow columns to expand to max_w before applying extra space equally. my $is_last_iter; for (;;) { my $span = ($avail_width - $min_width) / scalar( @$col_props); last if $span <= 0; $min_width = 0; my $next_will_be_last_iter = 1; for(my $j = 0; $j < scalar(@$col_props); $j++ ) { my $new_w = $calc_widths->[$j] + $span; if (!$is_last_iter && $new_w > $col_props->[$j]->{max_w}) { $new_w = $col_props->[$j]->{max_w} } if ($calc_widths->[$j] != $new_w ) { $calc_widths->[$j] = $new_w; $next_will_be_last_iter = 0; } $min_width += $new_w; } last if $is_last_iter; $is_last_iter = $next_will_be_last_iter; } return ($calc_widths,$avail_width); } 1; __END__ =pod =head1 NAME PDF::Table - A utility class for building table layouts in a PDF::API2 object. =head1 SYNOPSIS use PDF::API2; use PDF::Table; my $pdftable = new PDF::Table; my $pdf = new PDF::API2(-file => "table_of_lorem.pdf"); my $page = $pdf->page; # some data to layout my $some_data =[ ["1 Lorem ipsum dolor", "Donec odio neque, faucibus vel", "consequat quis, tincidunt vel, felis."], ["Nulla euismod sem eget neque.", "Donec odio neque", "Sed eu velit."], #... and so on ]; $left_edge_of_table = 50; # build the table layout $pdftable->table( # required params $pdf, $page, $some_data, x => $left_edge_of_table, w => 495, start_y => 500, start_h => 300, # some optional params next_y => 750, next_h => 500, padding => 5, padding_right => 10, background_color_odd => "gray", background_color_even => "lightblue", #cell background color for even rows ); # do other stuff with $pdf $pdf->saveas(); ... =head1 EXAMPLE For a complete working example or initial script look into distribution`s 'examples' folder. =head1 DESCRIPTION This class is a utility for use with the PDF::API2 module from CPAN. It can be used to display text data in a table layout within a PDF. The text data must be in a 2D array (such as returned by a DBI statement handle fetchall_arrayref() call). The PDF::Table will automatically add as many new pages as necessary to display all of the data. 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. Also a (non)repeated header row with different layout properties can be specified. See the L section for complete documentation of every parameter. =head1 METHODS =head2 new() my $pdf_table = new PDF::Table; =over =item Description Creates a new instance of the class. (to be improved) =item Parameters There are no parameters. =item Returns Reference to the new instance =back =head2 table() my ($final_page, $number_of_pages, $final_y) = table($pdf, $page, $data, %settings) =over =item Description Generates a multi-row, multi-column table into an existing PDF document based on provided data set and settings. =item Parameters $pdf - a PDF::API2 instance representing the document being created $page - a PDF::API2::Page instance representing the current page of the document $data - an ARRAY reference to a 2D data structure that will be used to build the table %settings - HASH with geometry and formatting parameters. For full %settings description see section L below. This method will add more pages to the pdf instance as required based on the formatting options and the amount of data. =item Returns The return value is a 3 items list where $final_page - The first item is a PDF::API2::Page instance that the table ends on $number_of_pages - The second item is the count of pages that the table spans on $final_y - The third item is the Y coordinate of the table bottom so that additional content can be added in the same document. =item Example my $pdf = new PDF::API2; my $page = $pdf->page(); my $data = [ ['foo1','bar1','baz1'], ['foo2','bar2','baz2'] ]; my %settings = ( x => 10, w => 570, start_y => 220, start_h => 180, ); my ($final_page, $number_of_pages, $final_y) = $pdftable->table( $pdf, $page, $data, %options ); =back =head3 Table settings =head4 Mandatory There are some mandatory parameteres for setting table geometry and position across page(s) =over =item B - X coordinate of upper left corner of the table. Left edge of the sheet is 0. B can be any whole number satisfying 0 =< X < PageWidth B No default value x => 10 =item B - Y coordinate of upper left corner of the table at the initial page. B can be any whole number satisfying 0 < start_y < PageHeight (depending on space availability when embedding a table) B No default value start_y => 327 =item B - width of the table starting from X. B can be any whole number satisfying 0 < w < PageWidth - x B No default value w => 570 =item B - Height of the table on the initial page B can be any whole number satisfying 0 < start_h < PageHeight - Current Y position B No default value start_h => 250 =back =head4 Optional =over =item B - Height of the table on any additional page B can be any whole number satisfying 0 < next_h < PageHeight B Value of param B<'start_h'> next_h => 700 =item B - Y coordinate of upper left corner of the table at any additional page. B can be any whole number satisfying 0 < next_y < PageHeight B Value of param B<'start_y'> next_y => 750 =item B - Breaks long words (like serial numbers hashes etc.) by adding a space after every Nth symbol B can be any whole positive number B 20 max_word_length => 20 # Will add a space after every 20 symbols =item B - Padding applied to every cell =item B - top cell padding, overrides 'padding' =item B - right cell padding, overrides 'padding' =item B - left cell padding, overrides 'padding' =item B - bottom padding, overrides 'padding' B can be any whole positive number B 0 B $padding padding => 5 # all sides cell padding padding_top => 8, # top cell padding, overrides 'padding' padding_right => 6, # right cell padding, overrides 'padding' padding_left => 2, # left cell padding, overrides 'padding' padding_bottom => undef # bottom padding will be 5 as it will fallback to 'padding' =item B - Width of table border lines. =item B - Width of horizontal border lines. Overrides 'border' value. =item B - Width of vertical border lines. Overrides 'border' value. B can be any whole positive number. When set to 0 will disable border lines. B 1 border => 3 # border width is 3 horizontal_borders => 1 # horizontal borders will be 1 overriding 3 vertical_borders => undef # vertical borders will be 3 as it will fallback to 'border' =item B - Width of vertical border lines. Overrides 'border' value. B Color specifier as 'name' or 'HEX' B 'black' border_color => 'red' =item B - instance of PDF::API2::Resource::Font defining the fontf to be used in the table B can be any PDF::API2::Resource::* type of font B 'Times' with UTF8 encoding font => $pdf->corefont("Helvetica", -encoding => "utf8") =item B - Default size of the font that will be used across the table B can be any positive number B 12 font_size => 16 =item B - Font color for all rows =item B - Font color for odd rows =item B - Font color for even rows =item B - Background color for odd rows =item B - Background color for even rows B Color specifier as 'name' or 'HEX' B 'black' font on 'white' background font_color => '#333333' font_color_odd => 'purple' font_color_even => '#00FF00' background_color_odd => 'gray' background_color_even => 'lightblue' =item B - Desired row height but it will be honored only if row_height > font_size + padding_top + padding_bottom B can be any whole positive number B font_size + padding_top + padding_bottom row_height => 24 =item B - CODE reference to a function that returns a PDF::API2::Page instance. 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. For example you can use it to put Page Title, Page Frame, Page Numbers and other staff that you need. 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. Don't forget that your function must return a page object created with PDF::API2 page() method. new_page_func => $code_ref =item B - HASH reference to specific settings for the Header row of the table. See section L below header_props => $hdr_props =item B - HASH reference to specific settings for each column of the table. See section L below column_props => $col_props =item B - HASH reference to specific settings for each column of the table. See section L below cell_props => $cel_props =item B - CODE reference to a function called with the current cell coordinates. If used the parameter 'cell_render_hook' must be a function reference. It is most useful for creating a url link inside of a cell. The following example adds a link in the first column of each non-header row: cell_render_hook => sub { my ($page, $first_row, $row, $col, $x, $y, $w, $h) = @_; # Do nothing except for first column (and not a header row) return unless ($col == 0); return if ($first_row); # Create link my $value = $list_of_vals[$row-1]; my $url = "https://${hostname}/app/${value}"; my $annot = $page->annotation(); $annot->url( $url, -rect => [$x, $y, $x+$w, $y+$h] ); }, =back =head4 Header Row Properties If the 'header_props' parameter is used, it should be a hashref. Passing an empty HASH will trigger a header row initialised with Default values. There is no 'data' variable for the content, because the module asumes that 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. =over =item B - instance of PDF::API2::Resource::Font defining the fontf to be used in the header row B can be any PDF::API2::Resource::* type of font B 'font' of the table. See table parameter 'font' for more details. =item B - Font size of the header row B can be any positive number B 'font_size' of the table + 2 =item B - Font color of the header row B Color specifier as 'name' or 'HEX' B '#000066' =item B - Background color of the header row B Color specifier as 'name' or 'HEX' B #FFFFAA =item B - Flag showing if header row should be repeated on every new page B 0,1 1-Yes/True, 0-No/False B 0 =item B - Alignment of text in the header row. B One of 'left', 'right', 'center' B Same as column alignment (or 'left' if undefined) my $hdr_props = { font => $pdf->corefont("Helvetica", -encoding => "utf8"), font_size => 18, font_color => '#004444', bg_color => 'yellow', repeat => 1, justify => 'center' }; =back =head4 Column Properties If the 'column_props' parameter is used, it should be an arrayref of hashrefs, 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. 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. Each hashref can contain any of the keys shown below: =over =item B - Minimum width of this column. Auto calculation will try its best to honour this param but aplying it is NOT guaranteed. B can be any whole number satisfying 0 < min_w < w B Auto calculated =item B - Maximum width of this column. Auto calculation will try its best to honour this param but aplying it is NOT guaranteed. B can be any whole number satisfying 0 < max_w < w B Auto calculated =item B - instance of PDF::API2::Resource::Font defining the fontf to be used in this column B can be any PDF::API2::Resource::* type of font B 'font' of the table. See table parameter 'font' for more details. =item B - Font size of this column B can be any positive number B 'font_size' of the table. =item B - Font color of this column B Color specifier as 'name' or 'HEX' B 'font_color' of the table. =item B - Background color of this column B Color specifier as 'name' or 'HEX' B undef =item B - Alignment of text in this column B One of 'left', 'right', 'center' B 'left' Example: my $col_props = [ {},# This is an empty hash so the next one will hold the properties for the second column from left to right. { min_w => 100, # Minimum column width of 100. max_w => 150, # Maximum column width of 150 . justify => 'right', # Right text alignment font => $pdf->corefont("Helvetica", -encoding => "latin1"), font_size => 10, font_color=> 'blue', background_color => '#FFFF00', }, # etc. ]; =back NOTE: If 'min_w' and/or 'max_w' parameter is used in 'col_props', have in mind that it may be overriden by the calculated minimum/maximum cell witdh so that table can be created. When this happens a warning will be issued with some advises what can be done. In cases of a conflict between column formatting and odd/even row formatting, 'col_props' will override odd/even. =head4 Cell Properties If the 'cell_props' parameter is used, it should be an arrayref with arrays of hashrefs (of the same dimension as the data array) with one hashref for each cell of the table. Each hashref can contain any of the keys shown below: =over =item B - instance of PDF::API2::Resource::Font defining the fontf to be used in this cell B can be any PDF::API2::Resource::* type of font B 'font' of the table. See table parameter 'font' for more details. =item B - Font size of this cell B can be any positive number B 'font_size' of the table. =item B - Font color of this cell B Color specifier as 'name' or 'HEX' B 'font_color' of the table. =item B - Background color of this cell B Color specifier as 'name' or 'HEX' B undef =item B - Alignment of text in this cell B One of 'left', 'right', 'center' B 'left' Example: my $cell_props = [ [ #This array is for the first row. If header_props is defined it will overwrite these settings. { #Row 1 cell 1 background_color => '#AAAA00', font_color => 'yellow', }, # etc. ], [#Row 2 { #Row 2 cell 1 background_color => '#CCCC00', font_color => 'blue', }, { #Row 2 cell 2 background_color => '#BBBB00', font_color => 'red', }, # etc. ], # etc. ]; OR my $cell_props = []; $cell_props->[1][0] = { #Row 2 cell 1 background_color => '#CCCC00', font_color => 'blue', }; =back NOTE: In case of a conflict between column, odd/even and cell formating, cell formating will overwrite the other two. In case of a conflict between header row and cell formating, header formating will override cell. =head2 text_block() my ($width_of_last_line, $ypos_of_last_line, $left_over_text) = text_block( $txt, $data, %settings) =over =item Description Utility method to create a block of text. The block may contain multiple paragraphs. It is mainly used internaly but you can use it from outside for placing formated text anywhere on the sheet. NOTE: This method will NOT add more pages to the pdf instance if the space is not enough to place the string inside the block. Leftover text will be returned and has to be handled by the caller - i.e. add a new page and a new block with the leftover. =item Parameters $txt - a PDF::API2::Page::Text instance representing the text tool $data - a string that will be placed inside the block %settings - HASH with geometry and formatting parameters. =item Reuturns The return value is a 3 items list where $width_of_last_line - Width of last line in the block $final_y - The Y coordinate of the block bottom so that additional content can be added after it $left_over_text - Text that was did not fit in the provided box geometry. =item Example # PDF::API2 objects my $page = $pdf->page; my $txt = $page->text; my %settings = ( x => 10, y => 570, w => 220, h => 180 #OPTIONAL PARAMS lead => $font_size | $distance_between_lines, align => "left|right|center|justify|fulljustify", hang => $optional_hanging_indent, Only one of the subsequent 3params can be given. They override each other.-parspace is the weightest parspace => $optional_vertical_space_before_first_paragraph, flindent => $optional_indent_of_first_line, fpindent => $optional_indent_of_first_paragraph, indent => $optional_indent_of_text_to_every_non_first_line, ); my ( $width_of_last_line, $final_y, $left_over_text ) = $pdftable->text_block( $txt, $data, %settings ); =back =head1 VERSION 0.9.7 =head1 AUTHOR Daemmon Hughes =head1 DEVELOPMENT Further development since Ver: 0.02 - Desislav Kamenov =head1 COPYRIGHT AND LICENSE Copyright (C) 2006 by Daemmon Hughes, portions Copyright 2004 Stone Environmental Inc. (www.stone-env.com) All Rights Reserved. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.4 or, at your option, any later version of Perl 5 you may have available. =head1 PLUGS =over =item by Daemmon Hughes Much of the work on this module was sponsered by Stone Environmental Inc. (www.stone-env.com). The text_block() method is a slightly modified copy of the one from Rick Measham's PDF::API2 tutorial at http://pdfapi2.sourceforge.net/cgi-bin/view/Main/YourFirstDocument =item by Desislav Kamenov (@deskata on Twitter) The development of this module was supported by SEEBURGER AG (www.seeburger.com) till year 2007 Thanks to my friends Krasimir Berov and Alex Kantchev for helpful tips and QA during development of versions 0.9.0 to 0.9.5 Thanks to all GitHub contributors! =back =head1 CONTRIBUTION Hey PDF::Table is on GitHub. You are more than welcome to contribute! https://github.com/kamenov/PDF-Table =head1 SEE ALSO L =cut PDF-Table-0.9.14/examples/row_height.pl000755 000765 000024 00000001402 12717162234 017651 0ustar00desistaff000000 000000 #!/usr/bin/env perl use warnings; use strict; use diagnostics; use PDF::API2; use PDF::Table; my $pdftable = PDF::Table->new(); my $pdf = PDF::API2->new( -file => "row_height.pdf" ); my $page = $pdf->page(); $pdf->mediabox('A4'); # A4 as defined by PDF::API2 is h=842 w=545 for portrait my $data = []; # some data to layout foreach my $num ( 1 .. 25 ) { push( @$data, [ 'foo' . $num, 'bar' . $num ] ); } # build the table layout $pdftable->table( # required params $pdf, $page, $data, x => 10, w => 150, start_y => 750, next_y => 700, start_h => 200, next_h => 500, # some optional params border => 1, font_size => 10, max_word_length => 15, padding => 5, row_height => 30, ); $pdf->saveas(); PDF-Table-0.9.14/examples/header.pl000755 000765 000024 00000002061 12717162234 016744 0ustar00desistaff000000 000000 #!/usr/bin/env perl use warnings; use strict; use diagnostics; #Please use TABSTOP=4 for best view use PDF::API2; use PDF::Table; my $pdftable = new PDF::Table; my $pdf = new PDF::API2( -file => "headers.pdf" ); my $page = $pdf->page(); $pdf->mediabox('A4'); # A4 as defined by PDF::API2 is h=842 w=545 for portrait # some data to layout my $some_data = [ [ 'HeaderA', 'HeaderB' ], [ 'foo', 'bar' ], [ 'one', 'two' ], [ 'thr', 'four score and seven years ago our fathers brought forth' ], [ 'fiv', 'six' ], [ 'sev', 'abcdefghijklmnopqrstuvwxyz' ], ]; # build the table layout $pdftable->table( # required params $pdf, $page, $some_data, x => 10, w => 220, start_y => 700, next_y => 700, start_h => 62, next_h => 62, # some optional params border => 0, font_size => 20, max_word_length => 13, header_props => { background_color => 'yellow', repeat => 1 }, cell_props => [ [], [ { background_color => 'red' }, { background_color => 'blue' } ], ], ); $pdf->saveas(); PDF-Table-0.9.14/examples/sample1.pl000755 000765 000024 00000005635 12717162234 017070 0ustar00desistaff000000 000000 #!/usr/bin/env perl use warnings; use strict; use diagnostics; =pod This example file gives an overview of the functionalities provided by PDF::Table Also it can be used to bootstrap your code. =cut #Please use TABSTOP=4 for best view use PDF::API2; use PDF::Table; my $pdftable = new PDF::Table; my $pdf = new PDF::API2( -file => "table_of_lorem.pdf" ); my $page = $pdf->page(); $pdf->mediabox('A4'); # A4 as defined by PDF::API2 is h=842 w=545 for portrait # some data to layout my $some_data = [ [ 'Header', 'Row', 'Test' ], [ '1 Lorem ipsum dolor', 'Donec odio neque, faucibus vel', 'consequat quis, tincidunt vel, felis.' ], [ 'Nulla euismod sem eget neque.', 'Donec odio neque', 'Sed eu velit.' ], [ 'Az sym bulgarin', "i ne razbiram DESI\ngorniq \nezik", "zatova reshih da dobavq edin ili dva novi reda" ], [ 'da dobavq edin dva reda', 'v tozi primer', 'na bulgarski ezik s latinica' ], [ '1 Lorem ipsum dolor', 'Donec odio neque, faucibus vel', 'consequat quis, tincidunt vel, felis.' ], [ 'Nulla euismod sem eget neque.', 'Donec odio neque', 'Sed eu velit.' ], [ 'Az sym bulgarin', 'i ne razbiram gorniq ezik', 'zatova reshih' ], [ 'da dobavq edin dva reda', 'v tozi primer', 'na bulgarski ezik s latinica' ], ]; # build the table layout $pdftable->table( # required params $pdf, $page, $some_data, # Geometry of the document x => 50, -w => 495 , # dashed params supported for backward compatibility. dash/non-dash params can be mixed start_y => 792, next_y => 700, -start_h => 400, next_h => 500, # some optional params for fancy results -padding => 3, padding_right => 10, background_color_odd => 'lightblue', background_color_even => "#EEEEAA", #cell background color for even rows header_props => { bg_color => "#F0AAAA", font => $pdf->corefont( "Helvetica", -encoding => "utf8" ), font_size => 14, font_color => "#006600", repeat => 1 }, column_props => [ {}, #no properties for the first column { min_w => 250, justify => "right", font => $pdf->corefont( "Times", -encoding => "latin1" ), font_size => 14, font_color => 'white', background_color => '#8CA6C5', }, ], cell_props => [ [ #This is the first(header) row of the table and here wins %header_props { background_color => '#000000', font_color => 'blue', }, # etc. ], [ #Row 2 { #Row 2 cell 1 background_color => '#000000', font_color => 'white', }, { #Row 2 cell 2 background_color => '#AAAA00', font_color => 'red', }, { #Row 2 cell 3 background_color => '#FFFFFF', font_color => 'green', }, # etc. ], [ #Row 3 { #Row 3 cell 1 background_color => '#AAAAAA', font_color => 'blue', }, # etc. ], # etc. ], ); $pdf->saveas(); PDF-Table-0.9.14/examples/header_repeat_with_cell_props.pl000755 000765 000024 00000004210 12717162234 023557 0ustar00desistaff000000 000000 #!/usr/bin/env perl use warnings; use strict; use diagnostics; #Please use TABSTOP=4 for best view use PDF::API2; use PDF::Table; my $pdftable = new PDF::Table; my $pdf = new PDF::API2( -file => "header_repeat_with_cell_props.pdf" ); my $page = $pdf->page(); $pdf->mediabox('A4'); # A4 as defined by PDF::API2 is h=842 w=545 for portrait # some data to layout my $some_data = [ [ 'Header', 'Row', 'Test' ], [ '1 Lorem ipsum dolor', 'Donec', 'consequat quis, tincidunt vel, felis.' ], [ '2 Lorem ipsum dolor', 'Donec super long text goes here to provoke a text block', 'consequat quis, tincidunt vel, felis.' ], [ '3 Lorem ipsum dolor', 'Donec', 'consequat quis, tincidunt vel, felis.' ], [ '4 Lorem ipsum dolor', 'Donec super long text goes here to provoke a text block', 'consequat quis, tincidunt vel, felis.' ], [ '5 Lorem ipsum dolor', 'Donec', 'consequat quis, tincidunt vel, felis.' ], [ '6 Lorem ipsum dolor', 'Donec', 'consequat quis, tincidunt vel, felis.' ], [ '7 Lorem ipsum dolor', 'Donec', 'consequat quis, tincidunt vel, felis.' ], [ '8 Lorem ipsum dolor', 'Donec', 'consequat quis, tincidunt vel, felis.' ], [ '9 Lorem ipsum dolor', 'Donec', 'consequat quis, tincidunt vel, felis.' ], ]; # build the table layout my $cell_props = []; $cell_props->[2][1] = { background_color => '#000000', font_color => 'blue', justify => 'left' }; $cell_props->[4][1] = { background_color => '#000000', font_color => 'red', justify => 'center' }; $cell_props->[6][1] = { background_color => '#000000', font_color => 'yellow', justify => 'right' }; $pdftable->table( # required params $pdf, $page, $some_data, x => 10, w => 350, start_y => 780, next_y => 780, start_h => 200, next_h => 200, padding => 10, # some optional params font_size => 10, padding_right => 10, horizontal_borders => 1, header_props => { bg_color => "silver", font => $pdf->corefont( "Helvetica", -encoding => "utf8" ), font_size => 20, font_color => "#006600", #justify => 'left', repeat => 1, }, cell_props => $cell_props ); $pdf->saveas(); PDF-Table-0.9.14/examples/table_of_lorem.pdf000644 000765 000024 00000027020 13121140631 020605 0ustar00desistaff000000 000000 %PDF-1.4 %͵ 1 0 obj << /Type /Catalog /PageLayout /SinglePage /PageMode /UseNone /Pages 2 0 R /ViewerPreferences << /NonFullScreenPageMode /UseNone >> >> endobj 2 0 obj << /Type /Pages /Count 1 /Kids [ 5 0 R ] /MediaBox [ 0 0 595 842 ] /Resources 3 0 R >> endobj 3 0 obj << /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] >> endobj 4 0 obj << /Producer (PDF::API2 2.031 [linux]) >> endobj 5 0 obj << /Type /Page /Contents [ 8 0 R 10 0 R 11 0 R 12 0 R ] /Parent 2 0 R /Resources << /Font << /HelvCBA~1495121573 6 0 R /TiRoCBB~1495121573 7 0 R /TiRoCBC~1495121573 9 0 R >> /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] >> >> endobj 6 0 obj << /Type /Font /Subtype /Type1 /BaseFont /Helvetica /Encoding << /Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences [ 0 /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /space /exclam /quotedbl /numbersign /dollar /percent /ampersand /quotesingle /parenleft /parenright /asterisk /plus /comma /hyphen /period /slash /zero /one /two /three /four /five /six /seven /eight /nine /colon /semicolon /less /equal /greater /question /at /A /B /C /D /E /F /G /H /I /J /K /L /M /N /O /P /Q /R /S /T /U /V /W /X /Y /Z /bracketleft /backslash /bracketright /asciicircum /underscore /grave /a /b /c /d /e /f /g /h /i /j /k /l /m /n /o /p /q /r /s /t /u /v /w /x /y /z /braceleft /bar /braceright /asciitilde /bullet /Euro /bullet /quotesinglbase /florin /quotedblbase /ellipsis /dagger /daggerdbl /circumflex /perthousand /Scaron /guilsinglleft /OE /bullet /Zcaron /bullet /bullet /quoteleft /quoteright /quotedblleft /quotedblright /bullet /endash /emdash /tilde /trademark /scaron /guilsinglright /oe /bullet /zcaron /Ydieresis /space /exclamdown /cent /sterling /currency /yen /brokenbar /section /dieresis /copyright /ordfeminine /guillemotleft /logicalnot /hyphen /registered /macron /degree /plusminus /twosuperior /threesuperior /acute /mu /paragraph /periodcentered /cedilla /onesuperior /ordmasculine /guillemotright /onequarter /onehalf /threequarters /questiondown /Agrave /Aacute /Acircumflex /Atilde /Adieresis /Aring /AE /Ccedilla /Egrave /Eacute /Ecircumflex /Edieresis /Igrave /Iacute /Icircumflex /Idieresis /Eth /Ntilde /Ograve /Oacute /Ocircumflex /Otilde /Odieresis /multiply /Oslash /Ugrave /Uacute /Ucircumflex /Udieresis /Yacute /Thorn /germandbls /agrave /aacute /acircumflex /atilde /adieresis /aring /ae /ccedilla /egrave /eacute /ecircumflex /edieresis /igrave /iacute /icircumflex /idieresis /eth /ntilde /ograve /oacute /ocircumflex /otilde /odieresis /divide /oslash /ugrave /uacute /ucircumflex /udieresis /yacute /thorn /ydieresis ] >> /FirstChar 32 /LastChar 255 /Name /HelvCBA~1495121573 /Widths [ 278 278 355 556 556 889 667 191 333 333 389 584 278 333 278 278 556 556 556 556 556 556 556 556 556 556 278 278 584 584 584 556 1015 667 667 722 722 667 611 778 722 278 500 667 556 833 722 778 667 778 722 667 611 722 667 944 667 667 611 278 278 278 469 556 333 556 556 500 556 556 278 556 556 222 222 500 222 833 556 556 556 556 333 500 278 556 500 722 500 500 500 334 260 334 584 350 556 350 222 556 333 1000 556 556 333 1000 667 333 1000 350 611 350 350 222 222 333 333 350 556 1000 333 1000 500 333 944 350 500 667 278 333 556 556 556 556 260 556 333 737 370 556 584 333 737 333 400 584 333 333 333 556 537 278 333 333 365 556 834 834 834 611 667 667 667 667 667 667 1000 722 667 667 667 667 278 278 278 278 722 722 778 778 778 778 778 584 778 722 722 722 722 667 667 611 556 556 556 556 556 556 889 500 556 556 556 556 278 278 278 278 556 556 556 556 556 556 556 584 611 556 556 556 556 500 556 500 ] >> endobj 7 0 obj << /Type /Font /Subtype /Type1 /BaseFont /Times-Roman /Encoding << /Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences [ 0 /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /space /exclam /quotedbl /numbersign /dollar /percent /ampersand /quotesingle /parenleft /parenright /asterisk /plus /comma /hyphen /period /slash /zero /one /two /three /four /five /six /seven /eight /nine /colon /semicolon /less /equal /greater /question /at /A /B /C /D /E /F /G /H /I /J /K /L /M /N /O /P /Q /R /S /T /U /V /W /X /Y /Z /bracketleft /backslash /bracketright /asciicircum /underscore /grave /a /b /c /d /e /f /g /h /i /j /k /l /m /n /o /p /q /r /s /t /u /v /w /x /y /z /braceleft /bar /braceright /asciitilde /bullet /Euro /bullet /quotesinglbase /florin /quotedblbase /ellipsis /dagger /daggerdbl /circumflex /perthousand /Scaron /guilsinglleft /OE /bullet /Zcaron /bullet /bullet /quoteleft /quoteright /quotedblleft /quotedblright /bullet /endash /emdash /tilde /trademark /scaron /guilsinglright /oe /bullet /zcaron /Ydieresis /space /exclamdown /cent /sterling /currency /yen /brokenbar /section /dieresis /copyright /ordfeminine /guillemotleft /logicalnot /hyphen /registered /macron /degree /plusminus /twosuperior /threesuperior /acute /mu /paragraph /periodcentered /cedilla /onesuperior /ordmasculine /guillemotright /onequarter /onehalf /threequarters /questiondown /Agrave /Aacute /Acircumflex /Atilde /Adieresis /Aring /AE /Ccedilla /Egrave /Eacute /Ecircumflex /Edieresis /Igrave /Iacute /Icircumflex /Idieresis /Eth /Ntilde /Ograve /Oacute /Ocircumflex /Otilde /Odieresis /multiply /Oslash /Ugrave /Uacute /Ucircumflex /Udieresis /Yacute /Thorn /germandbls /agrave /aacute /acircumflex /atilde /adieresis /aring /ae /ccedilla /egrave /eacute /ecircumflex /edieresis /igrave /iacute /icircumflex /idieresis /eth /ntilde /ograve /oacute /ocircumflex /otilde /odieresis /divide /oslash /ugrave /uacute /ucircumflex /udieresis /yacute /thorn /ydieresis ] >> /FirstChar 32 /LastChar 255 /Name /TiRoCBB~1495121573 /Widths [ 250 333 408 500 500 833 778 180 333 333 500 564 250 333 250 278 500 500 500 500 500 500 500 500 500 500 278 278 564 564 564 444 921 722 667 667 722 611 556 722 722 333 389 722 611 889 722 722 556 722 667 556 611 722 722 944 722 722 611 333 278 333 469 500 333 444 500 444 500 444 333 500 500 278 278 500 278 778 500 500 500 500 333 389 278 500 500 722 500 500 444 480 200 480 541 350 500 350 333 500 444 1000 500 500 333 1000 556 333 889 350 611 350 350 333 333 444 444 350 500 1000 333 980 389 333 722 350 444 722 250 333 500 500 500 500 200 500 333 760 276 500 564 333 760 333 400 564 300 300 333 500 453 250 333 300 310 500 750 750 750 444 722 722 722 722 722 722 889 667 611 611 611 611 333 333 333 333 722 722 722 722 722 722 722 564 722 722 722 722 722 722 556 500 444 444 444 444 444 444 667 444 444 444 444 444 278 278 278 278 500 500 500 500 500 500 500 564 500 500 500 500 500 500 500 500 ] >> endobj 8 0 obj << /Filter [ /FlateDecode ] /Length 69 >> stream xSPp QPH)svr344542457V04QI#O&$3(EIƉ =C+0 +6 endstream endobj 9 0 obj << /Type /Font /Subtype /Type1 /BaseFont /Times-Roman /Encoding << /Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences [ 0 /.notdef /acute /caron /circumflex /dieresis /grave /macron /ring /tilde /breve /ogonek /dotaccent /hungarumlaut /cedilla /dblgrave /controlSI /controlDLE /controlDC1 /controlDC2 /controlDC3 /controlDC4 /controlNAK /controlSYN /controlETB /controlCAN /controlEM /controlSUB /controlESC /controlFS /controlGS /dotlessi /dotlessj /space /exclam /quotedbl /numbersign /dollar /percent /ampersand /quotesingle /parenleft /parenright /asterisk /plus /comma /hyphen /period /slash /zero /one /two /three /four /five /six /seven /eight /nine /colon /semicolon /less /equal /greater /question /at /A /B /C /D /E /F /G /H /I /J /K /L /M /N /O /P /Q /R /S /T /U /V /W /X /Y /Z /bracketleft /backslash /bracketright /asciicircum /underscore /grave /a /b /c /d /e /f /g /h /i /j /k /l /m /n /o /p /q /r /s /t /u /v /w /x /y /z /braceleft /bar /braceright /asciitilde /controlDEL /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD /uniFFFD ] >> /FirstChar 32 /LastChar 255 /Name /TiRoCBC~1495121573 /Widths [ 250 333 408 500 500 833 778 180 333 333 500 564 250 333 250 278 500 500 500 500 500 500 500 500 500 500 278 278 564 564 564 444 921 722 667 667 722 611 556 722 722 333 389 722 611 889 722 722 556 722 667 556 611 722 722 944 722 722 611 333 278 333 469 500 333 444 500 444 500 444 333 500 500 278 278 500 278 778 500 500 500 500 333 389 278 500 500 722 500 500 444 480 200 480 541 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 250 ] >> endobj 10 0 obj << /Filter [ /FlateDecode ] /Length 253 >> stream xK D ρsE!Mq < C`RXo> stream x_o0ſy줊bR;M{hy7*>@T#$S$w9>FMDOj6a^șx9^p z6{mذ-O?%~rA)bOD_Oø[>롞ԯQD(Og[7^T)b|8=l#:o=*&L*yQ-h^eώvwu*+4_XUT\lAqmM17znQw{ ֐nsUH]>U1 \Jfck؜ Wty2Z6Cr3}í5)U9e#b}"izNHqwh ,vRUm9~Юkzm^ZeJO`Y,eva\L(!ĵd>d&]?Fr94FI2BFքR|D{7f(i;/3$c=?FFoD8>95ypHJ_,;"s#GG> stream xM U :w‹^@[b|B_B+dT'ULN-)Ҡ"~'4)9w4Hw'e'F6=0Q`CiMD;uEω-+=: endstream endobj xref 0 13 0000000000 65535 f 0000000015 00000 n 0000000164 00000 n 0000000266 00000 n 0000000335 00000 n 0000000392 00000 n 0000000635 00000 n 0000003826 00000 n 0000007015 00000 n 0000007159 00000 n 0000010294 00000 n 0000010624 00000 n 0000011257 00000 n trailer << /Info 4 0 R /Root 1 0 R /Size 13 >> startxref 11453 %%EOF PDF-Table-0.9.14/t/pod.t000644 000765 000024 00000000200 13121140560 014525 0ustar00desistaff000000 000000 use Test::More; eval "use Test::Pod 1.00"; plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; all_pod_files_ok();PDF-Table-0.9.14/t/manifest.t000644 000765 000024 00000000333 13121140560 015560 0ustar00desistaff000000 000000 #!perl -T use 5.006; use strict; use warnings FATAL => 'all'; use Test::More; my $min_tcm = 0.9; eval "use Test::CheckManifest $min_tcm"; plan skip_all => "Test::CheckManifest $min_tcm required" if $@; ok_manifest(); PDF-Table-0.9.14/t/PDF-Table.t000644 000765 000024 00000007371 13121140560 015421 0ustar00desistaff000000 000000 use Test::More tests => 11; use strict; use warnings; use lib 't/lib'; # Needed for 'make test' from project dirs use TestData qw(); use PDFAPI2Mock; BEGIN { use_ok('PDF::Table') } my ($col_widths); ($col_widths, undef) = PDF::Table::CalcColumnWidths( [ { min_w => 50, max_w => 50 }, { min_w => 50, max_w => 50 }, { min_w => 50, max_w => 50 }, { min_w => 50, max_w => 50 }, ], 400); is_deeply( $col_widths, [ 100, 100, 100, 100 ], 'CalcColumnWidths - even'); ($col_widths, undef) = PDF::Table::CalcColumnWidths( [ { min_w => 41, max_w => 51 }, { min_w => 58, max_w => 600 }, { min_w => 48, max_w => 48 }, ], 400); is_deeply( $col_widths, [ 51, 301, 48 ], 'CalcColumnWidths - uneven'); ($col_widths, undef) = PDF::Table::CalcColumnWidths( [ { min_w => 50, max_w => 50 }, { min_w => undef, max_w => 50 }, ], 400); is_deeply( $col_widths, [ 200, 200 ], 'CalcColumnWidths - undef'); my ($pdf, $page, $tab, @data, @required); @data = ( [ 'foo', 'bar', 'baz' ], ); @required = ( x => 10, w => 300, start_y => 750, next_y => 700, start_h => 40, next_h => 500, ); $pdf = PDF::API2->new; $page = $pdf->page; $tab = PDF::Table->new($pdf, $page); # # this tickles a bug (#34017) which causes an infinite loop # 'foo' =~ /(o)(o)/; $tab->table($pdf, $page, [@data], @required, border => 1, border_color => 'black', font_size => 12, background_color => 'gray', column_props => [ {}, { background_color => 'red' }, {}, ], cell_props => [ [ {}, {}, { background_color => 'blue' } ], ], ); ok($pdf->match( [[qw(translate 10 738)],[qw(text foo)]], [[qw(translate 110 738)],[qw(text bar)]], [[qw(translate 210 738)],[qw(text baz)]], ), 'text position'); ok($pdf->match( [[qw(rect 10 738 100 12)],[qw(fillcolor gray)]], [[qw(rect 110 738 100 12)],[qw(fillcolor red)]], [[qw(rect 210 738 100 12)],[qw(fillcolor blue)]], ), 'default header fillcolor'); ok($pdf->match( [[qw(gfx)],[qw(strokecolor black)],[qw(linewidth 1)]], [[qw(stroke)]], ), "draw borders"); $pdf = PDF::API2->new; $page = $pdf->page; $tab->table($pdf, $page, [@data], @required, border => 0, border_color => 'black', font_size => 12, column_props => [ {}, { justify => 'center' }, { justify => 'center' }, ], cell_props => [ [ { justify => 'center' }, {}, { justify => 'right' } ], ], ); ok($pdf->match( [[qw(translate 52.5 738)],[qw(text foo)]], [[qw(translate 152.5 738)],[qw(text bar)]], [[qw(translate 295 738)],[qw(text baz)]], ), 'justify right and center'); ok(!$pdf->match( [[qw(gfx)],[qw(strokecolor black)],[qw(linewidth 0)]], ), "don't set up zero-width borders"); # table is only 3 lines high (4*12 > 40). @data = ( [ 'foo', 'bar' ], [ 'one', 'two' ], [ 'thr', 'four score and seven years ago our fathers brought forth' ], [ 'fiv', 'six' ], [ 'sev', 'abcdefghijklmnopqrstuvwxyz' ], ); $pdf = PDF::API2->new; $page = $pdf->page; $tab->table($pdf, $page, [@data], @required, border => 0, font_size => 12, max_word_length => 13, cell_props => [ [], [ { background_color => 'blue' }, {} ], ], ); ok(1,'fake test because the one below is not working and must be fixed'); #ok($pdf->match( # [[qw(page)]], # [[qw(rect 10 714 20 12)],[qw(fillcolor blue)]], # [[qw(translate 10 714)],[qw(text thr)]], # [[qw(page)]], # [[qw(rect 10 688 20 12)],[qw(fillcolor blue)]], # [[qw(translate 10 688)],[qw(text -)]], #), 'keep cell_props values when row spans a page'); ok($pdf->match( [['text', 'abcdefghijklm nopqrstuvwxyz']], ), 'break long words on max_word_length'); PDF-Table-0.9.14/t/table.t000644 000765 000024 00000002063 13121140560 015043 0ustar00desistaff000000 000000 use strict; use warnings; use Test::More tests => 6; use lib 't/lib'; # Needed for 'make test' from project dirs use PDFAPI2Mock; BEGIN { use_ok('PDF::Table'); } local $SIG{__WARN__} = sub { my $message = shift; die $message; }; my $pdf = PDF::API2->new; my $page = $pdf->page; my $object = PDF::Table->new($pdf, $page); my $data = [ 'foo', 'bar', 'baz' ]; my $required = [ x => 10, w => 300, start_y => 750, next_y => 700, start_h => 40, next_h => 500 ]; ok($object->table($pdf, $page, [$data], @$required)); eval { $object->table('pdf', $page, [$data], @$required) }; like($@, qr/Error: Invalid pdf object received/); eval { $object->table($pdf, 'page', [$data], @$required) }; like($@, qr/Error: Invalid page object received/); eval { $object->table($pdf, $page, 'data', @$required) }; like($@, qr/Error: Invalid data received/); eval { $object->table($pdf, $page, 'data', 'required') }; like($@, qr/Odd number of elements in hash assignment/); done_testing(); PDF-Table-0.9.14/t/lib/000755 000765 000024 00000000000 13203531115 014335 5ustar00desistaff000000 000000 PDF-Table-0.9.14/t/Basics.t000644 000765 000024 00000006166 13121140560 015170 0ustar00desistaff000000 000000 use Test::More tests => 7; use strict; use warnings; use lib 't/lib'; # Needed for 'make test' from project dir use TestData; use PDFAPI2Mock; BEGIN { use_ok('PDF::Table'); } require_ok('PDF::Table'); my ( $pdf, $page, $tab, @data, %opts ); $pdf = PDF::API2->new(); $page = $pdf->page(); $tab = PDF::Table->new($pdf,$page); @data = ( [ 'foo', 'bar', 'baz' ], ); $tab->table( $pdf, $page, \@data, %TestData::required, ); #Check default font size ok( $pdf->match( [ [qw(font 1 12)], [qw(font 1 12)], [qw(font 1 12)] ] ), 'default font_size' ) || note explain $pdf; #Check default text placement ok( $pdf->match( [ [qw(translate 10 688)], [qw(text foo)] ], [ [qw(translate 110 688)], [qw(text bar)] ], [ [qw(translate 210 688)], [qw(text baz)] ], ), 'default text placement in one row' ) or note explain $pdf; #Check default splitting of long words @data = ( ['123456789012345678901234567890123456789012345678901234567890'], ); %opts = ( %TestData::required, w => 400, #override w so table() will not use text_block() ); $tab->table( $pdf, $page, \@data, %opts ); ok( $pdf->match( [ [ 'text', '12345678901234567890 12345678901234567890 12345678901234567890' ] ], ), 'default break long words on every 20th character' ) or note explain $pdf; # # Test header alignment if unspecified (should default to column alignment # if unspecified) # $pdf = PDF::API2->new(); $page = $pdf->page(); $tab = PDF::Table->new($pdf,$page); @data = ( [ 'head1', 'head2', 'head3'], [ 'foo', 'bar', 'baz' ], ); # Match column properties to default header properties my $col_props = [ { font_color => '#000066', font_size => 14, background_color => '#FFFFAA', justify => 'left' }, { font_color => '#000066', font_size => 14, background_color => '#FFFFAA', justify => 'center' }, { font_color => '#000066', font_size => 14, background_color => '#FFFFAA', justify => 'right' }, ]; %opts = ( %TestData::required, column_props => $col_props, ); $tab->table( $pdf, $page, \@data, %opts ); my @pdf_no_header_props = $pdf->getall; my $pdf2 = PDF::API2->new(); my $page2 = $pdf2->page(); my $tab2 = PDF::Table->new($pdf2,$page2); @data = ( [ 'head1', 'head2', 'head3'], [ 'foo', 'bar', 'baz' ], ); %opts = ( %TestData::required, header_props => { repeat => 1, }, column_props => $col_props, ); $tab2->table( $pdf2, $page2, \@data, %opts ); ok( $pdf2->match( \@pdf_no_header_props ), 'Header alignment matches column alignment if unspecified' ) or note explain $pdf2; $pdf = PDF::API2->new(); $page = $pdf->page(); @data = ( [0..2], [3..5], [6..8] ); my $cell_data; %opts = ( %TestData::required, cell_render_hook => sub { my ($page, $first_row, $row, $col, $x, $y, $w, $h) = @_; $cell_data .= "($row, $col), "; } ); $tab = PDF::Table->new( $pdf, $page ); $tab->table( $pdf2, $page2, \@data, %opts ); ok( $cell_data eq '(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0), (2, 1), (2, 2), ', 'The cell_render_hook() subroutine output is valid' ) or diag explain \$pdf; PDF-Table-0.9.14/t/lib/TestData.pm000644 000765 000024 00000000335 13121140560 016404 0ustar00desistaff000000 000000 package TestData; use strict; use warnings; our %test = ( a => 1 ); our %required = ( x => 10, w => 300, start_y => 700, next_y => 600, start_h => 100, next_h => 500, ); return 1; PDF-Table-0.9.14/t/lib/PDFAPI2Mock.pm000644 000765 000024 00000004057 13121140560 016537 0ustar00desistaff000000 000000 package PDFAPI2Mock; BEGIN { # Mock PDF::API2 # this is a mini MockObject with factory methods package Mock; sub new { return bless [] => shift; } sub get { my $self = shift; my $method = shift; # optional method name return $method ? grep( $_->[0] eq $method, @$self ) : @$self; } sub getall { my $self = shift; my @all; for (@$self) { push @all, ref( $_->[1] ) ? ( [ $_->[0] ], $_->[1]->getall ) : $_; } return @all; } sub match { my $self = shift; my $all = join( "\n", map { join( "\0", @$_ ) } $self->getall ); for (@_) { my $patt = join( "\n", map { join( "\0", @$_ ) } @$_ ); return 0 unless $all =~ /^$patt$/mcg; } return 1; } # class methods for creating object methods sub set_true { my $class = shift; for my $method (@_) { no strict 'refs'; *{ $class . '::' . $method } = sub { push @{ +shift }, [ $method, @_ ]; return 1 }; } } sub factory { my $class = shift; my $target = shift; my $method = shift; no strict 'refs'; *{ $class . '::' . $method } = sub { my $thing = $target->new; push @{ +shift }, [ $method, $thing ]; return $thing; }; } package PDF::API2; our @ISA = 'Mock'; __PACKAGE__->set_true(qw(corefont)); __PACKAGE__->factory( 'PDF::API2::Page', 'page' ); package PDF::API2::Page; our @ISA = 'Mock'; __PACKAGE__->factory( 'PDF::API2::Content', 'gfx' ); __PACKAGE__->factory( 'PDF::API2::Content::Text', 'text' ); package PDF::API2::Content; our @ISA = 'Mock'; __PACKAGE__->set_true( qw(strokecolor linewidth move hline vline fillcolor stroke rect fill)); package PDF::API2::Content::Text; our @ISA = 'Mock'; __PACKAGE__->set_true(qw(font fillcolor translate text)); sub advancewidth { shift; return 5 * length shift } } return 1; PDF-Table-0.9.14/util/pod2cpanhtml.pl000644 000765 000024 00000001305 13121140560 017227 0ustar00desistaff000000 000000 #!/usr/bin/env perl -w #This script has been taken from a forum somewhere in the vast Internet space :) #Its purpose is to generate the HTML from POD and apply some CSS as it will look like on CPAN #Typical use: perl pod2cpanhtml.pl lib/PDF/Table.pm pdftable.html use strict; use Pod::Simple::HTML; my $parser = Pod::Simple::HTML->new(); if (defined $ARGV[0]) { open IN, $ARGV[0] or die "Couldn't open $ARGV[0]: $!\n"; } else { *IN = *STDIN; } if (defined $ARGV[1]) { open OUT, ">$ARGV[1]" or die "Couldn't open $ARGV[1]: $!\n"; } else { *OUT = *STDOUT; } $parser->index(1); $parser->html_css('http://search.cpan.org/s/style.css'); $parser->output_fh(*OUT); $parser->parse_file(*IN);