This is like a continuation to my prev. question.
I managed to parse html, and also populate pdf tables (separately).
Now, i need to combine them and merge the html table content that i've to generate pdf content i need.
I've written some code, this generates blank pdf along with some runtime errors/warnings
Odd number of elements in hash assignment at E:/Perl/site/lib/PDF/Tabl
+e.pm line 230.
This is my code (a part of it):
use PDF::API2;
use PDF::Table;
use HTML::Parser;
use HTML::TableExtract;
$final_content = '<table border='1' width='50%' align='center'><tr><td
+><strong>Customer</td><td><strong>Total Samples</td><td><strong>SL Vi
+olations</td><td><strong>Avg Availability</td></tr><tr><td>
All Customers</td><td>183867</td><td>2102</td><td>98.85</td>
</td></tr></table><br><p><strong><h2><center>Customers Below 90% Avail
+able</center></h2></p><table border='1' width='50%' align='center'><t
+r><td><strong>Customer</td><td><strong>Total Samples</td><td><strong>
+SL Violations</td><td><strong>Availability</td></tr>
<tr><td>CD date </td><td>2256</td><td>913</td><td>59.53 %</td></tr>
<tr><td>QK - data</td><td>289</td><td>61</td><td>78.89 %</td></tr>
<tr><td>MW - verw</td><td>187</td><td>34</td><td>81.81 %</td></tr>
<tr><td>FY - werds</td><td>228</td><td>30</td><td>86.84 %</td></tr>
<tr><td>1dsfew - text</td><td>1064</td><td>124</td><td>88.34 %</td></t
+r>
<tr><td>1Zdfe - down</td><td>435</td><td>48</td><td>88.96 %</td></tr>
<tr><td>1vds - Corp</td><td>563</td><td>61</td><td>89.16 %</td></tr>
<tr><td>8Zer - Szerw</td><td>288</td><td>29</td><td>89.93 %</td></tr>
</tr></table>'; #### this i get from earlier part of program
$te = HTML::TableExtract->new( headers => ["Customer","Total Samples",
+"SL Violations","Availability"]);
$te->parse($final_content); #this is the content i pass
my $page=0;
my $tabs=0;
foreach $ts ($te->tables) {
print "Table (", join(',', $ts->coords), "):\n";
$page++;
foreach $row ($ts->rows) {
$t=join(",",@$row);
my @row_ele = split(/,/,$t);
push(@arr,[@row_ele]); #potential problem line, need to pus
+h the rows into an array, i think it returns a reference
print "@row_ele"."\n";
}
}
my $pdftable = new PDF::Table;
my $pdf = new PDF::API2(-file => "New.pdf");
# $some_data=[[1,2,3],[2,3,4]];########data needed in this format
+to print in pdf table
for($k=0;$k<$page;$k++)
{
print "page is now $k\n";
my $page = $pdf->page(1);
$pdftable->table(
# required params
$pdf,
$page,
@{$arr[$k]}, #############Problem line, not proper, some mist
+ake
-x => 10,
-start_y => 500,
-next_y => 700,
-start_h => 300,
-next_h => 500,
# some optional params
-w => 570,
-padding => 5,
-padding_right => 10,
-background_color_odd => "white",
-background_color_even => "yellow", #cell background color fo
+r even rows
);
}
$pdf->save;
I've marked potential problem lines...script genereates a pdf file called New.pdf
Where have i gone wrong?
One more thing: the documentation says the data to be printed in PDF table needs to be 2 Dimensional array.
UPDATE::
SOlved the problem, it was the array reference. (as pointed out by Anonymous).