Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^2: Making PDF Tables

by Anonymous Monk
on Oct 27, 2014 at 18:57 UTC ( [id://1105190]=note: print w/replies, xml ) Need Help??


in reply to Re: Making PDF Tables
in thread Making PDF Tables

That works, but the problem is when the data for the first table grows like in this situation:
my $some_data = [ ["1 Lorem ipsum dolor", "Donec odio neque, faucibus vel", "consequa +t quis, tincidunt vel, felis."], ["Nulla euismod sem eget neque.", "Donec odio neque", "Sed eu velit +."], ["1 Lorem ipsum dolor", "Donec odio neque, faucibus vel", "consequa +t quis, tincidunt vel, felis."], ["Nulla euismod sem eget neque.", "Donec odio neque", "Sed eu velit +."], ["1 Lorem ipsum dolor", "Donec odio neque, faucibus vel", "consequa +t quis, tincidunt vel, felis."], ["Nulla euismod sem eget neque.", "Donec odio neque", "Sed eu velit +."], ["1 Lorem ipsum dolor", "Donec odio neque, faucibus vel", "consequa +t quis, tincidunt vel, felis."], ["Nulla euismod sem eget neque.", "Donec odio neque", "Sed eu velit +."], ["1 Lorem ipsum dolor", "Donec odio neque, faucibus vel", "consequa +t quis, tincidunt vel, felis."], ["Nulla euismod sem eget neque.", "Donec odio neque", "Sed eu velit +."], ["1 Lorem ipsum dolor", "Donec odio neque, faucibus vel", "consequa +t quis, tincidunt vel, felis."], ["Nulla euismod sem eget neque.", "Donec odio neque", "Sed eu velit +."], ["1 Lorem ipsum dolor", "Donec odio neque, faucibus vel", "consequa +t quis, tincidunt vel, felis."], ["Nulla euismod sem eget neque.", "Donec odio neque", "Sed eu velit +."], ]; my $more_data = [ ["1 Lorem ipsum dolor", "Donec odio neque, faucibus vel", "consequa +t quis, tincidunt vel, felis."], ["Nulla euismod sem eget neque.", "Donec odio neque", "Sed eu velit +."], ]; ... #@tmp = @$some_data; @tmp = @$more_data; ...

It will overlap the second table.

Replies are listed 'Best First'.
Re^3: Making PDF Tables
by poj (Abbot) on Oct 27, 2014 at 19:15 UTC
    Increase the gap between the tables, 70 seems about right
    start_y => $boty - 70,
    Update : If that doesn't work, try increasing the start_h, next_h parameters and use $nextpage for the second table.
    my ($nextpage, undef, $boty) = $pdftable->table( $pdf, $page, $some_data, x => $left_edge_of_table, w => 495, start_y => 750, next_y => 750, start_h => 750, next_h => 750, padding => 5, padding_right => 10, background_color_odd => "gray", background_color_even => "lightblue", ); $pdftable->table( $pdf, $nextpage, $more_data, x => $left_edge_of_table, w => 500, start_y => $boty - 10, next_y => 750, start_h => $boty - 10, next_h => 750, padding => 5, padding_right => 10, background_color_odd => "navy", background_color_even => "red", #cell background color for even r +ows );
    poj
      Great example, here it is, this works, based in your code:
      use PDF::API2; use PDF::Table; my $pdftable = new PDF::Table; my $pdf = new PDF::API2(-file => "table_of_lorem.pdf"); my $page = $pdf->page; my $some_data = [ ["1 Lorem ipsum dolor", "Donec odio neque, faucibus vel", "consequa +t quis, tincidunt vel, felis."], ["Nulla euismod sem eget neque.", "Donec odio neque", "Sed eu velit +."], ["1 Lorem ipsum dolor", "Donec odio neque, faucibus vel", "consequa +t quis, tincidunt vel, felis."], ["Nulla euismod sem eget neque.", "Donec odio neque", "Sed eu velit +."], ["1 Lorem ipsum dolor", "Donec odio neque, faucibus vel", "consequa +t quis, tincidunt vel, felis."], ["Nulla euismod sem eget neque.", "Donec odio neque", "Sed eu velit +."], ["1 Lorem ipsum dolor", "Donec odio neque, faucibus vel", "consequa +t quis, tincidunt vel, felis."], ["Nulla euismod sem eget neque.", "Donec odio neque", "Sed eu velit +."], ["1 Lorem ipsum dolor", "Donec odio neque, faucibus vel", "consequa +t quis, tincidunt vel, felis."], ["Nulla euismod sem eget neque.", "Donec odio neque", "Sed eu velit +."], ["1 Lorem ipsum dolor", "Donec odio neque, faucibus vel", "consequa +t quis, tincidunt vel, felis."], ["Nulla euismod sem eget neque.", "Donec odio neque", "Sed eu velit +."], ["1 Lorem ipsum dolor", "Donec odio neque, faucibus vel", "consequa +t quis, tincidunt vel, felis."], ["Nulla euismod sem eget neque.", "Donec odio neque", "Sed eu velit +."], ["1 Lorem ipsum dolor", "Donec odio neque, faucibus vel", "consequa +t quis, tincidunt vel, felis."], ["Nulla euismod sem eget neque.", "Donec odio neque", "Sed eu velit +."], ["1 Lorem ipsum dolor", "Donec odio neque, faucibus vel", "consequa +t quis, tincidunt vel, felis."], ["Nulla euismod sem eget neque.", "Donec odio neque", "Sed eu velit +."], ["1 Lorem ipsum dolor", "Donec odio neque, faucibus vel", "consequa +t quis, tincidunt vel, felis."], ["Nulla euismod sem eget neque.", "Donec odio neque", "Sed eu velit +."], ["1 Lorem ipsum dolor", "Donec odio neque, faucibus vel", "consequa +t quis, tincidunt vel, felis."], ["Nulla euismod sem eget neque.", "Donec odio neque", "Sed eu velit +."], ["1 Lorem ipsum dolor", "Donec odio neque, faucibus vel", "consequa +t quis, tincidunt vel, felis."], ["Nulla euismod sem eget neque.", "Donec odio neque", "Sed eu velit +."], ["1 Lorem ipsum dolor", "Donec odio neque, faucibus vel", "consequa +t quis, tincidunt vel, felis."], ["Nulla euismod sem eget neque.", "Donec odio neque", "Sed eu velit +."], ["1 Lorem ipsum dolor", "Donec odio neque, faucibus vel", "consequa +t quis, tincidunt vel, felis."], ["Nulla euismod sem eget neque.", "Donec odio neque", "Sed eu velit +."], ]; my $more_data = [ ["X Lorem ipsum dolor", "Donec odio neque, faucibus vel", "consequa +t quis, tincidunt vel, felis."], ["Nulla euismod sem eget neque.", "Donec odio neque", "Sed eu velit +."], ["X Lorem ipsum dolor", "Donec odio neque, faucibus vel", "consequa +t quis, tincidunt vel, felis."], ["Nulla euismod sem eget neque.", "Donec odio neque", "Sed eu velit +."], ["X Lorem ipsum dolor", "Donec odio neque, faucibus vel", "consequa +t quis, tincidunt vel, felis."], ["Nulla euismod sem eget neque.", "Donec odio neque", "Sed eu velit +."], ["X Lorem ipsum dolor", "Donec odio neque, faucibus vel", "consequa +t quis, tincidunt vel, felis."], ["Nulla euismod sem eget neque.", "Donec odio neque", "Sed eu velit +."], ["X Lorem ipsum dolor", "Donec odio neque, faucibus vel", "consequa +t quis, tincidunt vel, felis."], ["Nulla euismod sem eget neque.", "Donec odio neque", "Sed eu velit +."], ]; my $more_extra_data = [ ["Y Lorem ipsum dolor", "Donec odio neque, faucibus vel", "consequa +t quis, tincidunt vel, felis.", "Header", "Header", "Header"], ["Nulla euismod sem eget neque.", "Donec odio neque", "Sed eu velit +.", "Header", "Header", "Header"], ["Y Lorem ipsum dolor", "Donec odio neque, faucibus vel", "consequa +t quis, tincidunt vel, felis.", "Header", "Header", "Header"], ["Nulla euismod sem eget neque.", "Donec odio neque", "Sed eu velit +.", "Header", "Header", "Header"], ["Y Lorem ipsum dolor", "Donec odio neque, faucibus vel", "consequa +t quis, tincidunt vel, felis.", "Header", "Header", "Header"], ["Nulla euismod sem eget neque.", "Donec odio neque", "Sed eu velit +.", "Header", "Header", "Header"], ["Y Lorem ipsum dolor", "Donec odio neque, faucibus vel", "consequa +t quis, tincidunt vel, felis.", "Header", "Header", "Header"], ["Nulla euismod sem eget neque.", "Donec odio neque", "Sed eu velit +.", "Header", "Header", "Header"], ["Y Lorem ipsum dolor", "Donec odio neque, faucibus vel", "consequa +t quis, tincidunt vel, felis.", "Header", "Header", "Header"], ["Nulla euismod sem eget neque.", "Donec odio neque", "Sed eu velit +.", "Header", "Header", "Header"], ]; my $more_last_data = [ ["Last Lorem ipsum dolor", "Donec odio neque, faucibus vel", "conse +quat quis, tincidunt vel, felis."], ["Nulla euismod sem eget neque.", "Donec odio neque", "Sed eu velit +."], ["Last Lorem ipsum dolor", "Donec odio neque, faucibus vel", "conse +quat quis, tincidunt vel, felis."], ["Nulla euismod sem eget neque.", "Donec odio neque", "Sed eu velit +."], ["Last Lorem ipsum dolor", "Donec odio neque, faucibus vel", "conse +quat quis, tincidunt vel, felis."], ]; my @tmp = @$some_data; my $left_edge_of_table = 50; my ($nextpage1, undef, $boty) = $pdftable->table( $pdf, $page, $some_data, x => $left_edge_of_table, w => 495, start_y => 750, next_y => 750, start_h => 750, next_h => 750, padding => 5, padding_right => 10, background_color_odd => "gray", background_color_even => "lightblue", ); my ($nextpage2, undef, $boty) = $pdftable->table( $pdf, $nextpage1, $more_data, x => $left_edge_of_table, w => 500, start_y => $boty - 10, next_y => 750, start_h => $boty - 10, next_h => 750, padding => 5, padding_right => 10, background_color_odd => "navy", background_color_even => "red", #cell background color for even r +ows ); my ($nextpage3, undef, $boty) = $pdftable->table( $pdf, $nextpage2, $more_extra_data, x => $left_edge_of_table, w => 500, start_y => $boty - 10, next_y => 750, start_h => $boty - 10, next_h => 750, padding => 5, padding_right => 10, background_color_odd => "yellow", background_color_even => "green", #cell background color for even + rows ); my ($nextpage4, undef, $boty) = $pdftable->table( $pdf, $nextpage3, $more_last_data, x => $left_edge_of_table, w => 500, start_y => $boty - 10, next_y => 750, start_h => $boty - 10, next_h => 750, padding => 5, padding_right => 10, background_color_odd => "blue", background_color_even => "#ffffff", #cell background color for ev +en rows ); $pdf->saveas();

      Hi, I don’t if you are still there, I have this almost working, I just can't figured why I am loosing all the settings in the last pdf page for the last table.
      Any thoughts?
      #!/usr/bin/perl use strict; use warnings; use PDF::API2; use PDF::Table; use Data::Dumper; my $pdftable = new PDF::Table; my $pdf = new PDF::API2(-file => "loren.pdf"); my $page_num = 1; my $some_data = [ ["1 Lorem ipsum dolor", "Donec odio neque, faucibus vel", "consequa +t quis, tincidunt vel, felis."], ["Nulla euismod sem eget neque.", "Donec odio neque", "Sed eu velit +."], ["1 Lorem ipsum dolor", "Donec odio neque, faucibus vel", "consequa +t quis, tincidunt vel, felis."], ["Nulla euismod sem eget neque.", "Donec odio neque", "Sed eu velit +."], ["1 Lorem ipsum dolor", "Donec odio neque, faucibus vel", "consequa +t quis, tincidunt vel, felis."], ["Nulla euismod sem eget neque.", "Donec odio neque", "Sed eu velit +."], ["1 Lorem ipsum dolor", "Donec odio neque, faucibus vel", "consequa +t quis, tincidunt vel, felis."], ["Nulla euismod sem eget neque.", "Donec odio neque", "Sed eu velit +."], ["1 Lorem ipsum dolor", "Donec odio neque, faucibus vel", "consequa +t quis, tincidunt vel, felis."], ["Nulla euismod sem eget neque.", "Donec odio neque", "Sed eu velit +."], ["1 Lorem ipsum dolor", "Donec odio neque, faucibus vel", "consequa +t quis, tincidunt vel, felis."], ["Nulla euismod sem eget neque.", "Donec odio neque", "Sed eu velit +."], ["1 Lorem ipsum dolor", "Donec odio neque, faucibus vel", "consequa +t quis, tincidunt vel, felis."], ["Nulla euismod sem eget neque.", "Donec odio neque", "Sed eu velit +."], ["1 Lorem ipsum dolor", "Donec odio neque, faucibus vel", "consequa +t quis, tincidunt vel, felis."], ["Nulla euismod sem eget neque.", "Donec odio neque", "Sed eu velit +."], ["1 Lorem ipsum dolor", "Donec odio neque, faucibus vel", "consequa +t quis, tincidunt vel, felis."], ["Nulla euismod sem eget neque.", "Donec odio neque", "Sed eu velit +."], ["1 Lorem ipsum dolor", "Donec odio neque, faucibus vel", "consequa +t quis, tincidunt vel, felis."], ["Nulla euismod sem eget neque.", "Donec odio neque", "Sed eu velit +."], ["1 Lorem ipsum dolor", "Donec odio neque, faucibus vel", "consequa +t quis, tincidunt vel, felis."], ["Nulla euismod sem eget neque.", "Donec odio neque", "Sed eu velit +."], ["1 Lorem ipsum dolor", "Donec odio neque, faucibus vel", "consequa +t quis, tincidunt vel, felis."], ["Nulla euismod sem eget neque.", "Donec odio neque", "Sed eu velit +."], ["1 Lorem ipsum dolor", "Donec odio neque, faucibus vel", "consequa +t quis, tincidunt vel, felis."], ["Nulla euismod sem eget neque.", "Donec odio neque", "Sed eu velit +."], ["LAST Lorem ipsum dolor", "Donec odio neque, faucibus vel", "conse +quat quis, tincidunt vel, felis."], ["Nulla euismod sem eget neque.", "Donec odio neque", "Sed eu velit +. LAST"], ]; my $more_data = [ ["X Lorem ipsum dolor", "Donec odio neque, faucibus vel", "consequa +t quis, tincidunt vel, felis."], ["Nulla euismod sem eget neque.", "Donec odio neque", "Sed eu velit +."], ["X Lorem ipsum dolor", "Donec odio neque, faucibus vel", "consequa +t quis, tincidunt vel, felis."], ["Nulla euismod sem eget neque.", "Donec odio neque", "Sed eu velit +."], ["X Lorem ipsum dolor", "Donec odio neque, faucibus vel", "consequa +t quis, tincidunt vel, felis."], ["Nulla euismod sem eget neque.", "Donec odio neque", "Sed eu velit +."], ["X Lorem ipsum dolor", "Donec odio neque, faucibus vel", "consequa +t quis, tincidunt vel, felis."], ["Nulla euismod sem eget neque.", "Donec odio neque", "Sed eu velit +."], ["X Lorem ipsum dolor", "Donec odio neque, faucibus vel", "consequa +t quis, tincidunt vel, felis."], ["Nulla euismod sem eget neque.", "Donec odio neque", "Sed eu velit +."], ]; my $more_extra_data = [ ["Y Lorem ipsum dolor", "Donec odio neque, faucibus vel", "consequa +t quis, tincidunt vel, felis.", "Header", "Header", "Header"], ["Nulla euismod sem eget neque.", "Donec odio neque", "Sed eu velit +.", "Header", "Header", "Header"], ["Y Lorem ipsum dolor", "Donec odio neque, faucibus vel", "consequa +t quis, tincidunt vel, felis.", "Header", "Header", "Header"], ["Nulla euismod sem eget neque.", "Donec odio neque", "Sed eu velit +.", "Header", "Header", "Header"], ["Y Lorem ipsum dolor", "Donec odio neque, faucibus vel", "consequa +t quis, tincidunt vel, felis.", "Header", "Header", "Header"], ["Nulla euismod sem eget neque.", "Donec odio neque", "Sed eu velit +.", "Header", "Header", "Header"], ["Y Lorem ipsum dolor", "Donec odio neque, faucibus vel", "consequa +t quis, tincidunt vel, felis.", "Header", "Header", "Header"], ["Nulla euismod sem eget neque.", "Donec odio neque", "Sed eu velit +.", "Header", "Header", "Header"], ["Y Lorem ipsum dolor", "Donec odio neque, faucibus vel", "consequa +t quis, tincidunt vel, felis.", "Header", "Header", "Header"], ["Nulla euismod sem eget neque.", "Donec odio neque", "Sed eu velit +.", "Header", "Header", "Header"], ]; my $more_last_data = [ ['xLast Lorem ipsum dolor', 'Donec odio neque, faucibus vel', 'cons +equat quis, tincidunt vel, felis.',], ['Nulla euismod sem eget neque.', 'Donec odio neque', 'Sed eu velit +.',], ['Last Lorem ipsum dolor', 'Donec odio neque, faucibus vel', 'conse +quat quis, tincidunt vel, felis.',], ['Nulla euismod sem eget neque.', 'Donec odio neque', 'Sed eu velit +.',], ['Last Lorem ipsum dolor', 'Donec odio neque, faucibus vel', 'conse +quat quis, tincidunt vel, felis.',], ] ; main_table( $pdf ); $pdf->saveas(); sub main_table { my $got_pdf = shift; my $left_edge_of_table = 70; # 50 my $page = newpage(); # first page my ($nextpage1, undef, $boty) = $pdftable->table( $got_pdf, $page, $some_data, x => $left_edge_of_table, # center main table on the page w => 650, # 495 width of main table on the page start_y => 500, # 750 height position of main table on the page next_y => 520, # 750 start_h => 500, # 750 next_h => 500, # 750 new_page_func => \&newpage, # it brigs header to other pages padding => 5, padding_right => 10, border => 0, background_color_odd => "gray", background_color_even => "lightblue", #column_props => [ map{{justify => 'center' }}1..3, ], ); my ($nextpage2, undef, $boty2) = $pdftable->table( $got_pdf, $nextpage1, $more_data, x => $left_edge_of_table, w => 655, # 500 start_y => $boty - 10, next_y => 500, # 750 start_h => $boty - 10, next_h => 500, # 750 padding => 5, # 5 padding_right => 10, # 10 background_color_odd => "navy", background_color_even => "red", #cell background color for even r +ows ); my ($nextpage3, undef, $boty3) = $pdftable->table( $got_pdf, $nextpage2, $more_extra_data, x => $left_edge_of_table, w => 655, # 500 start_y => $boty2 - 10, next_y => 500, # 750 start_h => $boty2 - 20, next_h => 500, # 750 padding => 5, padding_right => 10, background_color_odd => "yellow", background_color_even => "green", #cell background color for even + rows ); $pdftable->table( $got_pdf, $nextpage3, $more_last_data, x => $left_edge_of_table, w => 655, # 500 start_y => $boty3 - 10, next_y => 500, # 750 start_h => $boty3 - 10, next_h => 500, # 750 padding => 5, padding_right => 10, background_color_odd => "blue", background_color_even => "#ffffff", #cell background color for ev +en rows ); } sub newpage { my $page = $pdf->page; my $logo = "logo.jpg"; my $image = $pdf->image_jpeg($logo, 122, 35); my $gfx = $page->gfx; $gfx->image($image, 5, 550, 230, 57); # logo position and size on +page $page->mediabox(782,605); ##add stuff report_title($page); month_report($page); info($page); page_nr($page, $page_num++); return $page; } sub report_title { my $page = shift; $page->gfx->textlabel( # PDF::API2 method 416, 593, # x, y $pdf->corefont("Helvetica-Bold"), 11, # font, size "Accoount Report", # text -color => '#000000', -align => 'center', ); $page->gfx->textlabel( # PDF::API2 method 416, 577, # x, y $pdf->corefont("Helvetica"), 10, # font, size "XY Company, Inc.", # text -color => '#000000', -align => 'center', ); $page->gfx->textlabel( # PDF::API2 method 416, 565, # x, y $pdf->corefont("Helvetica"), 9, # font, size "100 Main Street", # text -color => '#000000', -align => 'center', ); } sub month_report { my $page = shift; my $date = get_date(); $page->gfx->textlabel( # PDF::API2 method 740, 595, # x, y $pdf->corefont("Helvetica"), 8, # font, size "Month: ", # text -color => '#000000', -align => 'right', ); $page->gfx->textlabel( # PDF::API2 method 777, 595, # x, y $pdf->corefont("Helvetica-Bold"), 8, # font, size "$date", # text -color => '#000000', -align => 'right', ); $page->gfx->textlabel( # PDF::API2 method 740, 555, # x, y $pdf->corefont("Helvetica"), 8, # font, size "Account: ", # text -color => '#000000', -align => 'right', ); $page->gfx->textlabel( # PDF::API2 method 770, 555, # x, y $pdf->corefont("Helvetica-Bold"), 8, # font, size "0000007", # text -color => '#000000', -align => 'right', ); } sub info { my $page = shift; $page->gfx->textlabel( # PDF::API2 method 416, 538, # first less move to left - second less move d +own # x, y $pdf->corefont("Helvetica-Bold"), 9, # font, size "My Company", # text -color => '#000000', -align => 'center', ); $page->gfx->textlabel( # PDF::API2 method 116, 538, # first less move to left - second less move d +own # x, y $pdf->corefont("Helvetica-Bold"), 9, # font, size "Number: wy000", # text -color => '#000000', -align => 'center', ); } sub page_nr { my $page = shift; my $num = shift; $page->gfx->textlabel( # PDF::API2 method 760, 15, # x, y $pdf->corefont("Helvetica"), 8, # font, size "Page $num", # text -color => '#808080', -align => 'right', ); } sub get_date { my ($mon, $mday, $year) = (localtime)[4,3,5]; return sprintf '%02d-%02d-%04d', $mon+1, $mday, $year+1900; }

      Thanks for the Help!
        Add new_page_func => \&newpage to all $pdftable->table() methods.
        poj

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2024-04-20 01:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found