<?xml version="1.0" encoding="windows-1252"?>
<node id="1004034" title="Set text size in table cell using PDF::Table" created="2012-11-15 11:15:08" updated="2012-11-15 11:15:08">
<type id="115">
perlquestion</type>
<author id="961">
Anonymous Monk</author>
<data>
<field name="doctext">
Hi Monks!&lt;br&gt;

I am trying to align a text inside of this pdf table cells and having no success. I can do the cell background color but to adjust the font size
doesn't work at all. I am trying to set the font size for the sub-heading texts like, "Primary Info" and "Secondary Info" and I just cant figure this one out,
I wish the module would give an easier access to these settings in an easier way. &lt;br&gt;
Has anyone worked with this before that could show me how or a better way of doing this? I am also trying to insert a line where the sum results are using a graphic
or something other than faking the sub totals line.&lt;br&gt;
Any Help is very appreciated. Here is the code sample to illustrade my frustration with this:&lt;br&gt;


&lt;p&gt;
&lt;readmore&gt;
&lt;code&gt;
#!/usr/bin/perl

use warnings;
use strict;
use PDF::API2;
use PDF::Table;
use Data::Dumper;

 my $pdftable = new PDF::Table;
 my $pdf = new PDF::API2(-file =&gt; "report.pdf");
 my $page = $pdf-&gt;page();
 $pdf-&gt;mediabox('A4');

 # some data to layout
 my $some_data =[
 
        ['Name', 'Address', 'Account', 'Amount',],
        ['','','','',],
        ['Primary Info','','','',],
        ['','','','',],
        ['1 - Charles Dawrwin',   '1 - Boston, MA',   '1 - 123456789',  '150.00'],
        ['2 - Arnold Shuwerts',   '2 - San Rose, CA', '2 - 844756485' , '250.00'],
        ['3 - Joe Doe',           '3 - Revere, MA',   '3 - 000034559',  '100.00'],
        ['4 - Mary Loo',          '4 - New York, NY', '4 - 333449687',  '125.00'],
        ['','','','',],
        ['','','','___________',],
        ['','Primary Sub Total','','550.00',],
        ['','','','',],
        ['1a - Mary Dawrwin',   '1a - Cambrigde, MA',   '1a - 123452789',  '550.00'],
        ['2a - Joe Doark',      '2a - Miami, FL',       '2a - 844726485' , '350.00'],
        ['','','','',],
        ['Secondary Info','','','',],
        ['','','','',],
        ['5 - John Dell',         '5 - Portland, ME', '5 - 111000384',   '55.00'],
        ['6 - Mary Loumain',      '6 - Cambridge, MA','6 - 000034569','1,000.00'],
        ['7 - Charles Town',      '7 - New Port, NH', '7 - 222299944',  '200.00'],
        ['8 - Jasmin Deen',       '8 - San Jose, CL', '8 - 000000122',  '255.00'],

        ['','','','___________',],
        ['','','Total:','$3,450.00',],
       
 ];

my $cell_props;
        
my $j = 0; 
foreach my $row ( @{$some_data} )    
{
my $k = 0;
    foreach my $cell ( @{$row} )
    {

        if ( ($cell eq 'Name') || ( $cell eq 'Address') || ( $cell eq 'Account') || ( $cell eq 'Amount') ) {
            
        $cell_props-&gt;[$j]-&gt;[$k] ={
                                    background_color =&gt; '#808080', #
                                    font_color       =&gt; '#FF0000', #
                                    justify =&gt; "center",
                                };

        }elsif ( ($cell eq 'Primary Info') || ($cell eq 'Secondary Info') ){

          $cell_props-&gt;[$j]-&gt;[$k] = {
                                    font =&gt; $pdf-&gt;corefont("Helvetica", -encoding =&gt; "utf8"),
                                    font_size =&gt; 15,
                                    background_color =&gt; '#FFCA00', #
                                    font_color       =&gt; '#4D4D4D', #
                                    justify =&gt; "left",
                                };
        }elsif ( ($cell eq 'Total:') ){

          $cell_props-&gt;[$j]-&gt;[$k] = {
                                    background_color =&gt; '#FFCA00', #
                                    font_color       =&gt; '#4D4D4D', #
                                    justify =&gt; "center",
                                };
                                
        }else {
            
        $cell_props-&gt;[$j]-&gt;[$k] = {
                                    font =&gt; $pdf-&gt;corefont("Helvetica", -encoding =&gt; "utf8"),
                                    font_size =&gt; 8,
                                    background_color =&gt; '#ffffff', #
                                    font_color       =&gt; '#000000', #
                                    justify =&gt; "center",
                                };
        }
        
    $k++;
    
    }
$j++;
}


 # build the table layout
 $pdftable-&gt;table(
         # required params
         $pdf,
         $page,
         $some_data, # 2D arrayref of text strings
         x =&gt; 50, #left_edge_of_table,
         -w =&gt; 495, # width of table. technically optional, but almost always a good idea to use
         start_y =&gt; 820, # baseline_of_first_line_on_first_page,
         next_y =&gt; 800, # baseline_of_first_line_on_succeeding_pages,
         -start_h =&gt; 800, # height_on_first_page,
         next_h =&gt; 500, # height_on_succeeding_pages,
        
         # some optional params
         -padding =&gt; 3, # cell padding
         padding_right =&gt; 10,  #right cell padding, overides -pad
         border =&gt; 0, # border width 0 for no border
         background_color_odd =&gt; '',
         background_color_even =&gt; '', #cell background color for even rows
        
        header_props =&gt;
            {
             min_w =&gt; 250,
             bg_color =&gt; "#808080",
             font =&gt; $pdf-&gt;corefont("Helvetica", -encoding =&gt; "utf8"),
             font_size =&gt; 13,
             font_color =&gt; "#000000",
             repeat =&gt; 1,
            },
        
         column_props   =&gt; [ map{{justify =&gt; 'center' }}1..4, ],
         

         cell_props     =&gt; 
             $cell_props,
             
  );

$pdf-&gt;saveas();
&lt;/code&gt;
&lt;/readmore&gt;
&lt;/p&gt;&lt;br&gt;
Thanks for looking!</field>
<field name="reputation">
10</field>
</data>
</node>
