Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks!

I am going crazy here trying to create dynamic pdf pages out of a database query, so far I can get the results from my database into the pdf-s OK, but I need to make sure that all the pdf pages are created in landscape mode, the table will be to big to fit otherwise, and the code I have so far only flips the first page correctly, I've tried everything like, "$page->rotate(90); #landscape", and no success. Also if anyone has worked on this stuff before and know if it is possible to add a link to one of the values returned from the database would be even more helpful for me.
Here is the code I am working on:

use strict; use CGI qw(:header); use CGI::Carp qw(fatalsToBrowser); use CGI qw/:standard/; use DBI; use PDF::API2; use PDF::Table; print header(); my $pdftable = new PDF::Table; my $pdf = new PDF::API2( -file => "pdf_table.pdf" ); $pdf->preferences( -singlepage => 1, -thumbs => 1, -fith => 1, ); my $page = $pdf->page; $page->mediabox(792,612); #*Connect with sql dbonce::: my $db = "LocalServer"; #... my $sql = "SELECT DISTINCT name, email ,phone, city, state FROM details LEFT OUTER JOIN main ON details.name = main.na +me "; my $sth = $dbh->prepare($sql)|| die $dbh->errstr; $sth->execute() or die "$!\n"; my $array_ref = $sth->fetchall_arrayref(); my $c=0; my $rows=750; my $left_edge_of_table = 10; $pdftable->table( # required params $pdf, $page, \@{$array_ref}, x => $left_edge_of_table, w => 495, # width of table start_y => 590, # top of page next_y => 800, # top of all other pages start_h => 500, # rows per page next_h => 500, # rows per page on all other pages # optional params padding => 5, padding_right => 10, background_color_odd => "gray", background_color_even => "lightblue", #cell background color for +even rows ); $pdf->saveas();

Thank you very much!!!

Replies are listed 'Best First'.
Re: Rotating a (PDF:::Table) Page Help!
by almut (Canon) on Mar 31, 2009 at 18:54 UTC

    Have you tried the new_page_func => $code_ref option to $pdftable->table()?  Its description sounds like it might do what you want:

    If used the parameter 'new_page_func' must be a function reference which when executed will create a new page and will return the object back to the module. For example you can use it to put Page Title, Page Frame, Page Numbers and other staff that you need. Also if you need some different type of paper size and orientation than the default A4-Portrait for example B2-Landscape you can use this function ref to set it up for you.
      Any where where I can look on how to use this 'new_page_func', the doc is not specific on that, I tried
      new_page_func  => "B2-Landscape", and
      new_page_func  => "B2",, it did not work still.
        the parameter 'new_page_func' must be a function reference

        This means, you need to pass it either the name of a subroutine, or an anonymous subroutine

        which when executed will create a new page

        ... so said subroutine must create a new page. Maybe something like the following, but bear in mind that I have no idea of how to use PDF::Table:

        new_page_func => sub { my ($pdf) = @_; # I don't know whether that's the parameter pa +ssed to this warn "Creating new page"; my $page = $pdf->page; # see PDF::API2 for pages ... do funky stuff with $page .... $page },