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

Monks I am using AxPoint to create reports in PDF format.AxPoint satisfies all of the requests except one,that is creating HTML tables.The question is, the report I create will have text,images and data in a table. I need to know is there any perl module that could help me to create a table in the pdf document.AxPoint doc. says that it has got a very basic support to HTML tables.So can you please help me find a module to do this.(Also, I know I can create a HTML table and convert that into an image and store in PDF but I dont want to do that). Thanks for your help

Replies are listed 'Best First'.
Re: Perl AxPoint and HTML tables
by Hofmator (Curate) on Jan 11, 2003 at 15:13 UTC
    It's quite easy to put together a routine that does output such a table. Be aware though, that this table doesn't have any fancy features you might expect from HTML tables. AxPoint has it's own format for generating tables.

    Below is a routine that does output what the AxPoint docs want. It's not tested with AxPoint, however.

    #!/usr/bin/perl use strict; use warnings; use List::Util qw/max sum/; $|++; # produces a layout of a table used in AxPoint # input: # $table_aref - reference to an array of arrays containing the eleme +nts # of the table # %options - additional (not compulsory) named parameters: # percent_size - reference to an array containg the size of the co +lumns # of the table (in percent of the total width) # [ will be calculated if not given ] # indent - string to use as indent for the different levels of the + layout # string will be used multiple times for deeper levels # # Assumptions: # - all rows of the table have the same length (amount of columns) # - if a percent_size array reference is given, the array has the +same length # as a row of the table. # # if any of these assumptions is wrong, the routine returns an empty + list # # normally returns an array of lines of the layouted table sub layout_table { my ($table_aref, %options) = @_; my @option_keys = qw/indent percent_size/; my ($indent, $percent_size_aref) = @options{@option_keys}; $indent = "\t" unless defined $indent; my $row_length = @{$table_aref->[0]}; for my $key (keys %options) { warn("Unrecognized option '$key' in 'layout_table'"), return unless grep { $key eq $_ } @option_keys; } if ($percent_size_aref) { # check length of percent_size return if @$percent_size_aref != $row_length; } else { # must calculate size of each column my @max_lengths = (0) x $row_length; for my $row (@$table_aref) { my $i = 0; @max_lengths = map { max($_, length $row->[$i++]) } @max_l +engths; } my $total_length = sum(@max_lengths); $percent_size_aref = [ map sprintf('%5.2f', 100*$_/$total_leng +th), @max_lengths ]; } my @result = ( '<table>' ); for my $row (@$table_aref) { return if $row_length != @$row; # check that all rows have sam +e no. columns push @result, $indent . '<row>'; for (my $i = 0; $i<$row_length; $i++) { my $p_size = $percent_size_aref->[$i]; push @result, $indent x 2 . qq/<col width="$p_size%">/; push @result, $indent x 3 . $row->[$i]; push @result, $indent x 2 . "</col>"; } push @result, $indent . '</row>' } push @result, '</table>'; return @result; } my @data; while (<DATA>) { push @data, [ split ]; } local $, = "\n"; print layout_table(\@data); print layout_table(\@data, percent_size => [50, 20, 20, 10] ); print layout_table(\@data, percent_size => [50, 20, 20, 10], indent => + ' ' ); print layout_table(\@data, perdent_size => [0.5, 0.2, 0.2, 0.1]); __DATA__ year income expense rest 2000 10 9 1 2001 20 13 7

    -- Hofmator