开发者

How can I make PDF tables from Perl?

开发者 https://www.devze.com 2022-12-11 07:26 出处:网络
Are there any perl modules to draw a table in a pdf at specified position with given rows and columns with an empty 开发者_开发技巧content in each cell?Two come to mind:

Are there any perl modules to draw a table in a pdf at specified position with given rows and columns with an empty 开发者_开发技巧content in each cell?


Two come to mind:

  • PDF::Table
  • PDF::Report::Table


I produced a simple table using PDF::Table like so:

use PDF::API2;
use PDF::Table;

my $pdf   = PDF::API2->new( -file => 'table.pdf' );
my $table = PDF::Table->new;
my $page  = $pdf->page;

my $data = [
  [ 'A1', 'A2', 'A3' ],
  [ 'B1', 'B2', 'B3' ],
  [ 'C1', 'C2', 'C3' ],
];

$table->table( $pdf, $page, $data,
               x       => 50,
               w       => 495,
               start_y => 750,
               next_y  => 700,
               start_h => 300,
               next_h  => 500,
);

$pdf->save;


And with PDF::Report::Table like this:

use PDF::Report;
use PDF::Report::Table;

my $pdf   = PDF::Report->new( PageSize => 'A4', PageOrientation => 'Portrait' );
my $table = PDF::Report::Table->new( $pdf );

my $data = [
  [ 'A1', 'A2', 'A3' ],
  [ 'B1', 'B2', 'B3' ],
  [ 'C1', 'C2', 'C3' ],
];

$pdf->openpage;
$pdf->setAddTextPos( 50, 50  );
$table->addTable( $data, 400 );   # 400 is table width

$pdf->saveAs( 'table.pdf' );
0

精彩评论

暂无评论...
验证码 换一张
取 消