Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^3: Looping in PDF::Table module

by Eliya (Vicar)
on Jul 25, 2013 at 14:07 UTC ( #1046350=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Looping in PDF::Table module
in thread Looping in PDF::Table module

The table() method returns 3 values:

  1. PDF::API2::Page object instance that the table ends on
  2. count of pages that the table spans
  3. y position of the table bottom

With that info (in particular 1 and 3) you can compute where to place the next table.  Sample code:

#!/usr/bin/perl -w use strict; use PDF::API2; use PDF::Table; my $pdftable = new PDF::Table; my $pdf = new PDF::API2(-file => "test.pdf"); my $page = $pdf->page; # some sample data (3 tables) my @data; for my $t (1..3) { my $table = []; for my $r (1..50) { push @$table, [ map "Table $t : $_$r", 'A'..'E' ]; } push @data, $table; } my $page_height = 700; my $top_y = 750; my $y = $top_y; for my $table (@data) { my ($p_last, undef, $y_bot) = $pdftable->table( $pdf, $page, $table, x => 50, w => 500, start_y => $y, next_y => $top_y, start_h => $page_height - ($top_y-$y), next_h => $page_height, # some optional params padding => 5, padding_right => 10, background_color_odd => "#eee", background_color_even => "#ddd", ); $page = $p_last; $y = $y_bot - 30; # vertical distance between tables if ($y < 50) { # page wrap $page = $pdf->page; $y = $top_y; } } $pdf->saveas();


Comment on Re^3: Looping in PDF::Table module
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1046350]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2015-07-03 22:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (57 votes), past polls