Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: PDF::Table seems to ignore column properties when there are but two columns

by rjt (Deacon)
on Jul 09, 2013 at 23:24 UTC ( #1043393=note: print w/ replies, xml ) Need Help??


in reply to PDF::Table seems to ignore column properties when there are but two columns

Works for me:

#!/usr/bin/env perl use 5.012; use warnings; use PDF::API2; use PDF::Table; my $pdftable = new PDF::Table; my $pdf = new PDF::API2(-file => 'test.pdf'); my $page = $pdf->page; # Table data, two columns my $scalar_song = [ [ '$ Sigils to the left of me', 'Arrows to the right ->' ], [ '$self->here', 'Stuck in the \[] with you' ] ]; my $col_props = [ { font => $pdf->corefont("Courier-Bold"), width => 250, font_color => 'blue', },{ font => $pdf->corefont("Courier-Bold"), width => 250, justify => 'right', font_color => 'green', } ]; $pdftable->table($pdf, $page, $scalar_song, -column_props => $col_props, -start_y => 750, -start_h => 300, -padding => 10, -x => 50, ); $pdf->saveas();

This generated a .pdf that had two columns of equal width, with the expected font, color, and justification settings. From what I can tell, PDF::Table seems to like leading hyphens on its top-level call, but not the column_props, but the examples in the documentation don't reflect that. Perhaps that is the issue?


Comment on Re: PDF::Table seems to ignore column properties when there are but two columns
Select or Download Code
Re^2: PDF::Table seems to ignore column properties when there are but two columns
by ted.byers (Scribe) on Jul 10, 2013 at 02:31 UTC

    Thanks, but alas, that didn't work for me when I tried to make the columns a different width. On my system, to make your code run, I had to provide a width to the table, in your call to table's constructor. That aside, the colours and aliognment worked fine, regardless of the presence or absence of the leading hyphens. And while it seems easy to make the columns equal width, there seems to be no way to make the right column consistentlly to take one fifth of the table width and the left column to take the rest.

    But to get a better test, try making the values in the left column arbitrary strings of variable length, and the right columns random currency values from $0.00 up to $999,999.99, and have three or four tables that use the same column properties, similar variability in the length of the strings in the left column but order of magnitude differences in the currency values between the tables (i.e. if in the first table the values are of the order of $10,000, make those in the second table of the order of $10, and those in the third of the order of $100,000). What you will see is that the layout of each table adapts to the data it is presenting, instead of the specs in the column properties. It is late, but I will work up an example of this sort in the morning, unless someone beats me to it.

    Thanks again

    Ted

      As promised, here is a sample that shows exactly what I am seeing:

      use strict; use warnings; use PDF::API2; use PDF::Table; my $pdf = new PDF::API2(-file => 'test5.pdf'); my $page = $pdf->page; # Table data, two columns my $table_data1 = [ [ 'balance forward', '$ 0.00' ], [ 'credit', '$ 100.00' ], [ 'debit', '$ 200.00'], [ 'balance', '$ 100.00' ], ]; my $table_data2 = [ [ 'balance forward', '$ 0.00' ], [ 'credit', '$ 10.00' ], [ 'debit', '$ 20.00'], [ 'balance', '$ 10.00' ], ]; my $table_data3 = [ [ 'balance forward', '$ 0.00' ], [ 'credit', '$ 100,000.00' ], [ 'debit', '$ 200,000.00'], [ 'balance', '$ 100,000.00' ], ]; my $table_data4 = [ [ 'balance forward', '$ 0.00' ], [ 'credit', '$ 1.00' ], [ 'debit', '$ 2.00'], [ 'balance balance balance balance', '$ 1.00' ], ]; my $col_props = [ { font => $pdf->corefont("Courier-Bold"), width => 250, font_color => 'blue', },{ font => $pdf->corefont("Courier-Bold"), width => 50, justify => 'right', font_color => 'green', } ]; my $pdftable1 = new PDF::Table; my ($end_page, $pages_spanned, $table_bot_y) = $pdftable1->table($pdf, + $page, $table_data1, -column_props => $col_props, -w => 300, -start_y => 750, -start_h => 300, -padding => 10, -x => 50, ); $table_bot_y -= 5; my $pdftable2 = new PDF::Table; ($end_page, $pages_spanned, $table_bot_y) = $pdftable1->table($pdf, $p +age, $table_data2, -column_props => $col_props, -w => 300, -start_y => $table_bot_y, -start_h => 300, -padding => 10, -x => 50, ); $table_bot_y -= 5; my $pdftable3 = new PDF::Table; ($end_page, $pages_spanned, $table_bot_y) = $pdftable1->table($pdf, $p +age, $table_data3, -column_props => $col_props, -w => 300, -start_y => $table_bot_y, -start_h => 300, -padding => 10, -x => 50, ); my $pdftable4 = new PDF::Table; $table_bot_y -= 5; $pdftable1->table($pdf, $page, $table_data4, -column_props => $col_props, -w => 300, -start_y => $table_bot_y, -start_h => 300, -padding => 5, -x => 50, ); $pdf->saveas();

      What you will see is that the third table gets a right column that is bigger than the rest, and then the fourth gets a right column that is narrower than the rest. What is required is that the table actually respect the properties specified in col_props, so that I can adjust the width of the right column so that it will always accomodate the largest currency value I know exists in my data, and use that in all tables using a given col_props variable.

      But I did notice that if I use a single instance of 'balance' in the fourth table, the table uses what looks like the same widths as those in the third table. Does the function 'table' actually modify col_props in those cases when it has the temerity to over-ride the values I coded? If so, what can be done about that?

      Thanks

      Ted

        Try using
        min_w => 250, max_w => 250,
        poj

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2014-07-12 14:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (240 votes), past polls