Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Help with PDF::API2::Simple and PDF::Table

by craret (Initiate)
on Feb 03, 2008 at 21:22 UTC ( [id://665865]=perlquestion: print w/replies, xml ) Need Help??

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

Hi All, I have been having some problems getting the two modules to speak the same language... My problem is that when I create a table in the PDFSimple class The PDF::Table creates pages without the headers and footers and inserts the table pages in-between the other pages... Any help would be much appreciated... even worth a virtual beer or 2 :) The code below is fully functional, you need to install PDF::API2::Simple and PDF::Table to make it work. If you run the .pl and look at the pdf that is created you will see what I mean with the table section not "attaching correctly" to the pdf. Thanks in advance.. Craig
#!/usr/bin/perl -w # require 5.005; use POSIX; use strict; use warnings; use PDF::API2::Simple; use PDF::Table; my $page_num = 1; my $pdf = PDF::API2::Simple->new( file => '04_headers.pdf', header => \&header, footer => \&footer ); my $pdftable = new PDF::Table; $pdf->add_font('VerdanaBold'); $pdf->add_font('Verdana'); $pdf->add_page(); #####PAGE 1###################### my $strokecol = $pdf->strokecolor; $pdf->next_line; $pdf->next_line; $pdf->set_font( 'VerdanaBold' ); $pdf->text('Hello World:', x => $pdf->margin_left+20, font_size => 10); $pdf->next_line; ###############PAGE2#################################3 $pdf->add_page(); $pdf->next_line; ############################### ################################ my $data =[ ["col1","col2","col3"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ["333","333","123"], ]; # build the table layout $pdftable->table( # required params $pdf->pdf, $pdf->current_page, $data, x => $pdf->margin_left, w => $pdf->effective_width, start_y => $pdf->margin_bottom + 500, next_y => 750, start_h => 500, next_h => 720, # some optional params new_page_func => $pdf->add_page(), header_props => { font => $pdf->current_font, font_size => 9, font_color => '#000000', bg_color => '#FF9046', repeat => 1, }, font => $pdf->current_font, font_size => 9, padding => 5, padding_right => 10, #background_color_odd => "gray", #background_color_even => "lightblue", #cell background color for even rows ); ################################################3 $pdf->add_page(); $pdf->save(); sub header { my $strokecolor = $pdf->strokecolor; my $y = $pdf->height - 20; my $x = ($pdf->width / 2); $pdf->stroke_color( '#555555' ); $pdf->next_line; $pdf->set_font( 'VerdanaBold' ); $pdf->text( 'Header ', x => $x, y => $y, font_size => 10, align =>'center' ); $pdf->y( $pdf->y - 5 ); } sub footer { my $strokecol = $pdf->strokecolor; $pdf->stroke_color( '#000000' ); $pdf->line( x => $pdf->margin_left, y => 40, to_x => $pdf->effective_width, to_y => 40, stroke => 'on', fill => 'off', width => 1 ); my $fillcolor = $pdf->fill_color; my $font = $pdf->current_font; $pdf->fill_color( '#000000' ); $pdf->set_font( 'VerdanaBold' ); $pdf->text( 'footer1', x => $pdf->margin_left, y => 30, font_size => 9, align => 'left' ); $pdf->next_line; $pdf->set_font( 'Verdana' ); $pdf->text( ' footer 2', x => $pdf->margin_left, y => 20, font_size => 8, align => 'left' ); $pdf->set_font( 'VerdanaBold' ); $pdf->text( 'Page ' . $page_num++, x => $pdf->effective_width, y => 20, align => 'right' ); $pdf->next_line; $pdf->set_font( 'Verdana' ); $pdf->text( 'footer 3', x => $pdf->margin_left, y => 10, font_size => 6, align => 'left' ); $pdf->fill_color( $fillcolor ); $pdf->current_font( $font ); }

Replies are listed 'Best First'.
Re: Help with PDF::API2::Simple and PDF::Table
by snoopy (Curate) on Feb 04, 2008 at 01:22 UTC
    PDF::Table has a habit of taking over the pagination. To keep control of the process, you may be better off to break this down into two stages.

  • create the table in a temporary pdf object
  • insert the table graphics, page-by-page, back into the main pdf

    You can then control where and how the pages from the table are inserted back into the main pdf.

    See Re^3: Add Border to a PDF file. This demonstrates copying pages from one pdf object to another.

      Thank you so much, that worked perfectly for me. I had to alter here and there to get the references right as you are using PDF::API2 and Im using PDF::API2::Simple. Thanks again!!
        Hi, monks! craret, can you, please post the working code? I am struggling with it for hours now and still didn't reach to a result. Thanks!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://665865]
Approved by moritz
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2024-04-26 00:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found