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

I am trying to use addTable from PDF::Report::Table. I am having trouble constructing the @data parameter.

Here is what I have tried:

use PDF::Report; use PDF::Report::Table; $main_rpt_path = "/home/ics/work/rpts/interimmtr_prebill.rpt"; $main_rpt_pdf = new PDF::Report('PageSize' => 'letter', 'PageOrientation' => 'Landscape',); $main_rpt_tbl_wrt = PDF::Report::Table->new($main_rpt_pdf); $main_rpt_tbl_wrt->addTable( build_table_writer_array($pt_column_headers_ref));

I see one error, but still get the same message. I missed the fact the width and color are parameters of addTable, so I corrected the call, and still got the same error.

$main_rpt_tbl_wrt->addTable( build_table_writer_array($pt_column_headers_ref), 10,10, 0xFFFFFF, 0xFFFFCC);

sub build_table_writer_array # $data -- an array ref of data # { my $data = shift @_; my $out_data_table = undef; $out_data_table = [[@$data],]; return $out_data_table; }

and here is the error I'm getting.

Use of uninitialized value in subtraction (-) at /usr/local/share/ +perl5/PDF/Report/Table.pm line 88. at /usr/local/share/perl5/PDF/Report/Table.pm line 88
I'd appreciate an example or help. Thanks.

Replies are listed 'Best First'.
Re: How to construct @data for PDF::Report::Table->addTable
by toolic (Bishop) on Aug 10, 2013 at 18:18 UTC
Re: How to construct @data for PDF::Report::Table->addTable
by poj (Abbot) on Aug 11, 2013 at 07:43 UTC
    If it's any help this produces a pdf but with warnings : Incorrect Table Geometry ! Setting bottom margin to end of sheet and doesn't set the 2nd page to Landscape.
    #!perl; use strict; use PDF::Report; use PDF::Report::Table; # test data rows=20 my $ar = testdata(20); my $pdf = new PDF::Report('PageSize' => 'LETTER', 'PageOrientation' => 'Landscape',); $pdf->newpage(); my ($width, $height) = $pdf->getPageDimensions(); my $margin = 50; $pdf->setAddTextPos($margin,$height-$margin); my $tbl_wrt = PDF::Report::Table->new($pdf); $tbl_wrt->addTable([@$ar],$width-$margin*2,5,'#ffffff','#ffffcc'); $pdf->saveAs('testA.pdf'); sub testdata{ my $rows = shift; my @ar=(); push @ar ,[$_, "col2-$_", "col3-$_", "col4-$_", "col5-$_", "a very wide column 6-$_ that has a lot of text and more than 1 line"] for (1..$rows); return \@ar; }
    poj