Anyone know how to start a new page after 20 lines pulling from a database using PDF::CREATE.
Here is what I have so far.
This prints heading on both pages and the line on both pages then prints all the output on the first page or second page which ever I specify $first to be. So the first page prints then the contents of the 2nd page prints on top of the print of the first page.
sub pdf_matrix
{
#use this to get max length of record. max(lenght(field))
BEGIN { unshift @INC, "lib", "../lib" }
($SQL) = @_;
$head1 = 'Year'; $head2 = 'Month'; $head3 = 'Original'; $head33 = 'Request';
$head4 = 'Modified'; $head5 = 'Re-run'; $head6 = 'Total';
my $dbh = DBI->connect('dbiB2B2P',"$mf_id" , "$mf_pw" if ($DBI::errstr) {print "<CENTER><B> $DBI::errstr </B></CENTER> ";}
my $sth = $dbh->prepare($SQL); if ($DBI::errstr) {print "$DBI::errstr";}
my $rc = $sth->execute; if ($DBI::errstr) {print "$DBI::errstr";}
my $pdf = new PDF::Create('filename' => 'D:/DWH_WEB/' . $file1,
'Version' => 1.2,
'PageMode' => 'UseOutlines',
'Author' => 'Fabien Tassin',
'Title' => 'My title',
);
my $root = $pdf->new_page('MediaBox' => [ 0, 0, 612, 792 ]);
# Add a page which inherits its attributes from $root
# Prepare 2 fonts
my $f1 = $pdf->font('Subtype' => 'Type1',
'Encoding' => 'WinAnsiEncoding',
'BaseFont' => 'Helvetica');
my $f2 = $pdf->font('Subtype' => 'Type1',
'Encoding' => 'WinAnsiEncoding',
'BaseFont' => 'Helvetica-Bold');
# Prepare a Table of Content
my $toc = $pdf->new_outline('Title' => 'Document',
'Destination' => $page);
$toc->new_outline('Title' => 'Section 1');
my $page = $root->new_page;
$page->stringc($f2, 20, 306, 775, "Info Center Reports"
$page->stringc($f2, 15, 306, 755, "Date Range"
$page->stringc($f2, 15, 306, 735, $SDATE ." and ". $EDATE);
$page->stringc($f2, 12, 101, 680, $head1);
$page->stringc($f2, 12, 183, 680, $head2);
$page->stringc($f2, 12, 265, 690, $head3);
$page->stringc($f2, 12, 347, 690, $head4);
$page->stringc($f2, 12, 429, 690, $head5);
$page->stringc($f2, 12, 511, 680, $head6);
$page->stringc($f2, 12, 265, 670, $head33);
$page->stringc($f2, 12, 347, 670, $head33);
$page->stringc($f2, 12, 429, 670, $head33);
$page->line (10,650, 600, 650);
# Add another page
my $page2 = $root->new_page;
$page2->stringc($f2, 20, 306, 775, "Info Center Reports"
$page2->stringc($f1, 15, 306, 755, "Date Range"
$page2->stringc($f1, 15, 306, 735, $SDATE ." and ". $EDATE);
$page2->stringc($f2, 12, 101, 680, $head1);
$page2->stringc($f2, 12, 183, 680, $head2);
$page2->stringc($f2, 12, 265, 690, $head3);
$page2->stringc($f2, 12, 347, 690, $head4);
$page2->stringc($f2, 12, 429, 690, $head5);
$page2->stringc($f2, 12, 511, 680, $head6);
$page2->stringc($f2, 12, 265, 670, $head33);
$page2->stringc($f2, 12, 347, 670, $head33);
$page2->stringc($f2, 12, 429, 670, $head33);
$page2->line (10,650, 600, 650);
# Add something to the first page
$line = 630;
$line1 = 630;
$line2 = 293;
# $col = 306;
$varlen1 = 1;
$first =$page;
while (($a1, $a2, $a3, $a4, $a5, $a6, $a7) = $sth->fetchrow())
{
#if ($varlen1 < length($a1)){$varlen1 = length($a1)}
#if ($varlen2 < length($a3)){$varlen2 = length($a3)}
#if ($varlen3 < length($a4)){$varlen3 = length($a4)}
#if ($varlen4 < length($a5)){$varlen4 = length($a5)}
#if ($varlen5 < length($a6)){$varlen5 = length($a6)}
#if ($varlen6 < length($a7)){$varlen6 = length($a7)}
#
#if ($varlen3 > length($head3)){$collength1 = $col - $varlen3 - 35;}else{$collength1 = $col - length($head3) - 35;}
#if ($varlen2 > length($head2)){$collength2 = $collength1 - $varlen2 - 70;}else{$collength2 = $collength1 - length($head2) - 70;}
#if ($varlen1 > length($head1)){$collength3 = $collength2 - $varlen1 - 70;}else{$collength3 = $collength2 - length($head1) - 70;}
# Add another page
$first->stringc($f1, 12,101, $line, $a1);
$first->stringc($f1, 12,183, $line, $a3);
$first->stringc($f2, 12,265, $line, $a4);
$first->stringc($f2, 12,347, $line, $a5);
$first->stringc($f1, 12,429, $line, $a6);
$first->stringc($f1, 12,511, $line, $a7);
$line = $line-20;
$line--;
if ($line < 550 ){$first = $page2; $line = 630; }
}
Here is what I have so far.
This prints heading on both pages and the line on both pages then prints all the output on the first page or second page which ever I specify $first to be. So the first page prints then the contents of the 2nd page prints on top of the print of the first page.
sub pdf_matrix
{
#use this to get max length of record. max(lenght(field))
BEGIN { unshift @INC, "lib", "../lib" }
($SQL) = @_;
$head1 = 'Year'; $head2 = 'Month'; $head3 = 'Original'; $head33 = 'Request';
$head4 = 'Modified'; $head5 = 'Re-run'; $head6 = 'Total';
my $dbh = DBI->connect('dbiB2B2P',"$mf_id" , "$mf_pw" if ($DBI::errstr) {print "<CENTER><B> $DBI::errstr </B></CENTER> ";}
my $sth = $dbh->prepare($SQL); if ($DBI::errstr) {print "$DBI::errstr";}
my $rc = $sth->execute; if ($DBI::errstr) {print "$DBI::errstr";}
my $pdf = new PDF::Create('filename' => 'D:/DWH_WEB/' . $file1,
'Version' => 1.2,
'PageMode' => 'UseOutlines',
'Author' => 'Fabien Tassin',
'Title' => 'My title',
);
my $root = $pdf->new_page('MediaBox' => [ 0, 0, 612, 792 ]);
# Add a page which inherits its attributes from $root
# Prepare 2 fonts
my $f1 = $pdf->font('Subtype' => 'Type1',
'Encoding' => 'WinAnsiEncoding',
'BaseFont' => 'Helvetica');
my $f2 = $pdf->font('Subtype' => 'Type1',
'Encoding' => 'WinAnsiEncoding',
'BaseFont' => 'Helvetica-Bold');
# Prepare a Table of Content
my $toc = $pdf->new_outline('Title' => 'Document',
'Destination' => $page);
$toc->new_outline('Title' => 'Section 1');
my $page = $root->new_page;
$page->stringc($f2, 20, 306, 775, "Info Center Reports"
$page->stringc($f2, 15, 306, 755, "Date Range"
$page->stringc($f2, 15, 306, 735, $SDATE ." and ". $EDATE);
$page->stringc($f2, 12, 101, 680, $head1);
$page->stringc($f2, 12, 183, 680, $head2);
$page->stringc($f2, 12, 265, 690, $head3);
$page->stringc($f2, 12, 347, 690, $head4);
$page->stringc($f2, 12, 429, 690, $head5);
$page->stringc($f2, 12, 511, 680, $head6);
$page->stringc($f2, 12, 265, 670, $head33);
$page->stringc($f2, 12, 347, 670, $head33);
$page->stringc($f2, 12, 429, 670, $head33);
$page->line (10,650, 600, 650);
# Add another page
my $page2 = $root->new_page;
$page2->stringc($f2, 20, 306, 775, "Info Center Reports"
$page2->stringc($f1, 15, 306, 755, "Date Range"
$page2->stringc($f1, 15, 306, 735, $SDATE ." and ". $EDATE);
$page2->stringc($f2, 12, 101, 680, $head1);
$page2->stringc($f2, 12, 183, 680, $head2);
$page2->stringc($f2, 12, 265, 690, $head3);
$page2->stringc($f2, 12, 347, 690, $head4);
$page2->stringc($f2, 12, 429, 690, $head5);
$page2->stringc($f2, 12, 511, 680, $head6);
$page2->stringc($f2, 12, 265, 670, $head33);
$page2->stringc($f2, 12, 347, 670, $head33);
$page2->stringc($f2, 12, 429, 670, $head33);
$page2->line (10,650, 600, 650);
# Add something to the first page
$line = 630;
$line1 = 630;
$line2 = 293;
# $col = 306;
$varlen1 = 1;
$first =$page;
while (($a1, $a2, $a3, $a4, $a5, $a6, $a7) = $sth->fetchrow())
{
#if ($varlen1 < length($a1)){$varlen1 = length($a1)}
#if ($varlen2 < length($a3)){$varlen2 = length($a3)}
#if ($varlen3 < length($a4)){$varlen3 = length($a4)}
#if ($varlen4 < length($a5)){$varlen4 = length($a5)}
#if ($varlen5 < length($a6)){$varlen5 = length($a6)}
#if ($varlen6 < length($a7)){$varlen6 = length($a7)}
#
#if ($varlen3 > length($head3)){$collength1 = $col - $varlen3 - 35;}else{$collength1 = $col - length($head3) - 35;}
#if ($varlen2 > length($head2)){$collength2 = $collength1 - $varlen2 - 70;}else{$collength2 = $collength1 - length($head2) - 70;}
#if ($varlen1 > length($head1)){$collength3 = $collength2 - $varlen1 - 70;}else{$collength3 = $collength2 - length($head1) - 70;}
# Add another page
$first->stringc($f1, 12,101, $line, $a1);
$first->stringc($f1, 12,183, $line, $a3);
$first->stringc($f2, 12,265, $line, $a4);
$first->stringc($f2, 12,347, $line, $a5);
$first->stringc($f1, 12,429, $line, $a6);
$first->stringc($f1, 12,511, $line, $a7);
$line = $line-20;
$line--;
if ($line < 550 ){$first = $page2; $line = 630; }
}