PhilterPaper / PDF-Table

Official repository for PDF::Table in Perl
https://www.catskilltech.com/FreeSW/product/PDF%2DTable/title/PDF%3A%3ATable/freeSW_full
Other
10 stars 15 forks source link

Stuck in infinite loop if #36

Closed djzort closed 6 years ago

djzort commented 7 years ago

If start_h parameter is too low, PDF::Table gets stuck in an infinite loop spewing the following error:

Use of uninitialized value $columns_number in numeric lt (<) at /home/dean/perl5/perlbrew/perls/perl-5.20.2/lib/site_perl/5.20.2/PDF/Table.pm line 817.

The $columns_number isnt defined because the line 617 code doesnt match, so $columns_number is never loaded while(scalar(@{$data}) and $cur_y-$row_h > $bot_marg)

kamenov commented 7 years ago

Hi, Thanks for reporting this. Would you propose a fix as you are more familiar with the context?

djzort commented 6 years ago

Heres an example derived from the examples dir

#!/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 = PDF::Table->new;
my $pdf      = PDF::API2->new( -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 => 640,
    next_y  => 700,
    start_h => 2,
    next_h  => 62,

    # some optional params
    border          => 0,
    font_size       => 20,
    font_underline  => [3 ,2],
    max_word_length => 13,
    header_props    => {
        background_color => 'yellow',
        repeat           => 1
    },
    cell_props => [
        [], [ { background_color => 'red' }, { background_color => 'blue' } ],
    ],
);

$pdf->saveas();
djzort commented 6 years ago

^ also on a second commit in the same PR

kamenov commented 6 years ago

Resolved with version 0.10.0